天天看點

usermod指令詳解

基礎指令學習目錄首頁

原網址:http://blog.51cto.com/urchin/987186

  1. 參考資料:usermod manpage 

 usermod - 修改使用者帳戶資訊 modify a user account

usermod [options] user_name

usermod 指令修改系統帳戶檔案來反映通過指令行指定的變化

選項(options)

  1. -a|--append  ##把使用者追加到某些組中,僅與-G選項一起使用 
  2. -c|--comment ##修改/etc/passwd檔案第五段comment 
  3. -d|--home    ##修改使用者的家目錄通常和-m選項一起使用 
  4. -e|--expiredate  ##指定使用者帳号禁用的日期,格式YY-MM-DD 
  5. -f|--inactive    ##使用者密碼過期多少天後采用就禁用該帳号,0表示密碼已過期就禁用帳号,-1表示禁用此功能,預設值是-1 
  6. -g|--gid     ##修改使用者的gid,改組一定存在
  7. -G|--groups  ##把使用者追加到某些組中,僅與-a選項一起使用 
  8. -l|--login   ##修改使用者的登入名稱 
  9. -L|--lock    ##鎖定使用者的密碼 
  10. -m|--move-home   ##修改使用者的家目錄通常和-d選項一起使用 
  11. -s|--shell   ##修改使用者的shell 
  12. -u|--uid     ##修改使用者的uid,該uid必須唯一 
  13. -U|--unlock  ##解鎖使用者的密碼 

示例(Examples):

1,建立使用者test,密碼test,另外添加usertest組

  1. #useradd test 
  2. #echo "test" | passwd --stdin test 
  3. #groupadd usertest 

2,把test使用者加入usertest組

  1. #usermod -aG usertest test ##多個組之間用空格隔開 
  2. #id test 
  3. uid=500(test) gid=500(test) groups=500(test),501(usertest) 

3,修改test使用者的家目錄

  1. #usermod -md /home/usertest 
  2. #ls /home 
  3. usertest 

4,修改使用者名

  1. #usermod -l urchin(新使用者名稱)  test(原來使用者名稱) 
  2. #id urchin 
  3. uid=500(urchin) gid=500(test) groups=500(test),501(usertest) 

5,鎖定urchin的密碼

  1. # sed -n '$p' /etc/shadow 
  2. urchin:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t \
  3. Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::: 
  4. #usermod -L urchin 
  5. urchin:!$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t \

6,解鎖urchin的密碼

  1. #usermod -U urchin 
  2. urchin:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t \ 

7,修改使用者的shell

  1. #sed '$!d' /etc/passwd 
  2. urchin:x:500:500::/home/usertest:/bin/bash 
  3. #usermod -s /bin/sh urchin 
  4. #sed -n '$p' /etc/passwd 
  5. urchin:x:500:500::/home/usertest:/bin/sh 

8,修改使用者的UID

  1. #usermod -u 578 urchin (UID必須唯一) 
  2. uid=578(urchin) gid=500(test) groups=500(test),501(usertest) 

9,修改使用者的GID

  1. #groupadd -g 578 test1 
  2. #usermod -g 578 urchin (578組一定要存在) 
  3. uid=578(urchin) gid=578(test1) groups=578(test1),501(usertest) 

10,指定帳号過期日期

  1. # usermod -e 2012-09-11 urchin 
  2. Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::15594: 

11,指定使用者帳号密碼過期多少天後,禁用該帳号

  1. # usermod -f 0 urchin 
  2. Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7:0:15594: 

注意(caution):

usermod不允許你改變正線上上的使用者帳号名稱。當usermod用來改變userID,必須确認這名user沒在電腦上執行任何程式

/etc/passwd

user_name:x:uid:gid:commnet:home:shell

/etc/shadow

username:passwd:lastchg:min:max:warn:inactive:expire:flag

--使用者名

--密碼

--從1970年1月1日起到上次修改密碼所經過的天數

--密碼再過幾天可以被變更(0表示随時可以改變)

--密碼再過幾天必須被變更(99999表示永不過期)

--密碼過期前幾天提醒使用者(預設為一周)

--密碼過期幾天後帳号被禁用

--從1970年1月1日算起,多少天後賬号失效