基礎指令學習目錄首頁
原網址:http://blog.51cto.com/urchin/987186
- 參考資料:usermod manpage
usermod - 修改使用者帳戶資訊 modify a user account
usermod [options] user_name
usermod 指令修改系統帳戶檔案來反映通過指令行指定的變化
選項(options)
- -a|--append ##把使用者追加到某些組中,僅與-G選項一起使用
- -c|--comment ##修改/etc/passwd檔案第五段comment
- -d|--home ##修改使用者的家目錄通常和-m選項一起使用
- -e|--expiredate ##指定使用者帳号禁用的日期,格式YY-MM-DD
- -f|--inactive ##使用者密碼過期多少天後采用就禁用該帳号,0表示密碼已過期就禁用帳号,-1表示禁用此功能,預設值是-1
- -g|--gid ##修改使用者的gid,改組一定存在
- -G|--groups ##把使用者追加到某些組中,僅與-a選項一起使用
- -l|--login ##修改使用者的登入名稱
- -L|--lock ##鎖定使用者的密碼
- -m|--move-home ##修改使用者的家目錄通常和-d選項一起使用
- -s|--shell ##修改使用者的shell
- -u|--uid ##修改使用者的uid,該uid必須唯一
- -U|--unlock ##解鎖使用者的密碼
示例(Examples):
1,建立使用者test,密碼test,另外添加usertest組
- #useradd test
- #echo "test" | passwd --stdin test
- #groupadd usertest
2,把test使用者加入usertest組
- #usermod -aG usertest test ##多個組之間用空格隔開
- #id test
- uid=500(test) gid=500(test) groups=500(test),501(usertest)
3,修改test使用者的家目錄
- #usermod -md /home/usertest
- #ls /home
- usertest
4,修改使用者名
- #usermod -l urchin(新使用者名稱) test(原來使用者名稱)
- #id urchin
- uid=500(urchin) gid=500(test) groups=500(test),501(usertest)
5,鎖定urchin的密碼
- # sed -n '$p' /etc/shadow
- urchin:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t \
- Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7:::
- #usermod -L urchin
- urchin:!$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t \
6,解鎖urchin的密碼
- #usermod -U urchin
- urchin:$6$1PwPVBn5$o.MIEYONzURQPvn/YqSp69kt2CIASvXhOnjv/t \
7,修改使用者的shell
- #sed '$!d' /etc/passwd
- urchin:x:500:500::/home/usertest:/bin/bash
- #usermod -s /bin/sh urchin
- #sed -n '$p' /etc/passwd
- urchin:x:500:500::/home/usertest:/bin/sh
8,修改使用者的UID
- #usermod -u 578 urchin (UID必須唯一)
- uid=578(urchin) gid=500(test) groups=500(test),501(usertest)
9,修改使用者的GID
- #groupadd -g 578 test1
- #usermod -g 578 urchin (578組一定要存在)
- uid=578(urchin) gid=578(test1) groups=578(test1),501(usertest)
10,指定帳号過期日期
- # usermod -e 2012-09-11 urchin
- Z5m4NN6bJyLjCG7S6vmji/PFDfbyITdm1WmtV45CfHV5vux/:15594:0:99999:7::15594:
11,指定使用者帳号密碼過期多少天後,禁用該帳号
- # usermod -f 0 urchin
- 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日算起,多少天後賬号失效