usermod [選項] 登錄名
usermod修改用戶基本信息。
(1).常用選項
-d,--home HOME_DIR 用戶的新主目錄 -g,--gid GROUP 強制GROUP為新主組 -G,--group GROUPS 新的附加組列表GROUPS(去除原有附加組) -L,--lock 鎖定用戶賬戶 -m,--move-home 將主目錄位置移至新位置(僅與-d一起使用) -m,--move-home 將主目錄內用移至新位置(僅與-d選項一起使用) -s,--shell SHELL 該用戶賬戶的新登錄shell -u,uid UID 用戶賬戶的新UID -U,--unlock 解鎖用戶賬戶
(2).實例
修改用戶UID
[root@xuexi ~]# useradd t1 [root@xuexi ~]# id t1 uid=1001(t1) gid=1001(t1) 組=1001(t1) [root@xuexi ~]# usermod -u 1111 t1 [root@xuexi ~]# id t1 uid=1111(t1) gid=1001(t1) 組=1001(t1)
修改登錄shell
[root@xuexi ~]# grep t1 /etc/passwd t1:x:1111:1001::/home/t1:/bin/bash [root@xuexi ~]# usermod -s /sbin/nologin t1 [root@xuexi ~]# grep t1 /etc/passwd t1:x:1111:1001::/home/t1:/sbin/nologin
修改主目錄並轉移主目錄內容,-m -d選項
[root@xuexi ~]# ls /home/ t1 xf [root@xuexi ~]# usermod -m -d /opt/t1 t1 [root@xuexi ~]# ls /home/ xf [root@xuexi ~]# ls /opt/ rh t1
修改說明信息(注釋信息)
[root@xuexi ~]# grep t1 /etc/passwd t1:x:1111:1001::/opt/t1:/sbin/nologin [root@xuexi ~]# usermod -c "hello world" t1 [root@xuexi ~]# grep t1 /etc/passwd t1:x:1111:1001:hello world:/opt/t1:/sbin/nologin