3.4 usermod命令

usermod命令介紹

  • usermod命令,更改用戶屬性的命令
  • 用戶的信息保存在/etc/passwd文件中

usermod命令用法

  • usermod和useradd命令用法類似

usermod格式

  • usermod -u 111 username 修改用戶的uid
  • usermod -g 123 username 這裏的123能夠是一個組名,也能夠是一個gid
  • usermod -d /home/asklea username 指定它的家目錄
  • usermod -s /sbin/nologin 指定它的shell
  • usermod -c 填寫帳號的備註信息
  • usermod -e 帳戶到期時間,格式「YYYY-MM-DD」
  • usermod -L 鎖定用戶,禁止登錄
  • usermod -U 解鎖用戶,容許登陸
  • usermod -G 擴展組,指定多個組
[root@localhost /]# id hanfeng      這個組不只包括了前面的gid,還能夠包括其餘的擴展組
uid=1000(hanfeng) gid=1000(hanfeng) 組=1000(hanfeng)
[root@localhost /]# groupadd ha1
[root@localhost /]# usermod -G ha1 hanfeng
[root@localhost /]# id hanfeng
uid=1000(hanfeng) gid=1000(hanfeng) 組=1000(hanfeng),1001(ha1)
[root@localhost /]# useradd user3
[root@localhost /]# usermod -G user3 hanfeng
[root@localhost /]# id hanfeng      這裏會發現指定-G以後,user3組替代了ha1組
uid=1000(hanfeng) gid=1000(hanfeng) 組=1000(hanfeng),1002(user3)
[root@localhost /]# usermod -G ha1,user3 hanfeng   同時添加多個組
[root@localhost /]# id hanfeng
uid=1000(hanfeng) gid=1000(hanfeng) 組=1000(hanfeng),1001(ha1),1002(user3)
一個用戶,它能夠屬於多個組,可是這個gid只有一個,咱們就能夠把除了gid以外的組,稱之爲擴展組
  • usermod -g 只能指定惟一一個組
[root@localhost /]# usermod -g ha1,user3 hanfeng
usermod:「ha1,user3」組不存在
[root@localhost /]# usermod -g ha1 hanfeng
[root@localhost /]# !id
id hanfeng
uid=1000(hanfeng) gid=1001(ha1) 組=1001(ha1),1002(user3)

usermod中-g和-G的區別

--g與-G的區別,-g只能只能指定一個組,而-G能夠指定多個組shell

  • useradd -G 指定一個或多個擴展用戶組
相關文章
相關標籤/搜索