[root@localhost /]# passwd 這裏直接就可更改root用戶的密碼 更改用戶 root 的密碼 。 新的 密碼: [root@localhost /]# passwd user3 在命令後面加上普通用戶,便可更改密碼 更改用戶 user3 的密碼 。 新的 密碼: 從新輸入新的 密碼: passwd:全部的身份驗證令牌已經成功更新。 [root@localhost /]# tail /etc/shadow 會看到user3這個多了一串加密的字符串 systemd-bus-proxy:!!:17459:::::: systemd-network:!!:17459:::::: dbus:!!:17459:::::: polkitd:!!:17459:::::: tss:!!:17459:::::: postfix:!!:17459:::::: sshd:!!:17459:::::: chrony:!!:17459:::::: hanfeng:!!:17470:0:99999:7::: user3:$6$1WEfFti.$gyRBbtnDqmAnsHDST5hIsE1oTlNhBAvasK3CTvCHIE2Bnga.mOZ7LWPR3xbfRz4vAtOlO6Z01iA47.evT90Nk0:17470:0:99999:7:::
[root@localhost ~]# head /etc/shadow root:$6$L6sm5Qq1aGOBJOIi$okCMP5JFEiDBpcaqreOtF54FA5.qyUTG/WfAj45Od7ONdM1Ut9buK9i4xdOcaBwUaX4x3oGd/wSJl4OWh0xOJ/::0:99999:7::: bin:*:17110:0:99999:7::: daemon:*:17110:0:99999:7::: adm:*:17110:0:99999:7::: lp:*:17110:0:99999:7::: sync:*:17110:0:99999:7::: shutdown:*:17110:0:99999:7::: halt:*:17110:0:99999:7::: mail:*:17110:0:99999:7::: operator:*:17110:0:99999:7:::
[root@hf-01 ~]# passwd -l hanfeng 會發現user10用戶的密碼被鎖定了 鎖定用戶 hanfeng 的密碼 。 passwd: 操做成功 [root@hf-01 ~]# tail -n7 /etc/shadow hanfeng:!!$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
在密碼文件的/etc/shadow中,會發現hanfeng用戶的密碼加上兩個歎號!!。說明它被鎖定了
[root@hf-01 ~]# passwd -u hanfeng 解鎖用戶 hanfeng 的密碼。 passwd: 操做成功 [root@hf-01 ~]# tail -n7 /etc/shadow hanfeng:$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
在/etc/shadow的密碼文件中,會發現hanfeng用戶下的兩個歎號 !! 消失了,說明該用戶解鎖成功。
[root@hf-01 ~]# usermod -L hanfeng [root@hf-01 ~]# !tail tail -n7 /etc/shadow hanfeng:!$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
在/etc/shadow密碼文件中,會發現密碼位置出現了一個歎號 ! ,無論是出現一個歎號,仍是兩個歎號,只要是歎號開頭了,就表示該用戶被鎖定了,不能登陸了。
[root@hf-01 ~]# usermod -U hanfeng [root@hf-01 ~]# !tail tail -n7 /etc/shadow hanfeng:$6$jV74kWmS$GPP5amnrGjHQuAxqAAxyKHmLp6lOXd64pWl1YxVu5VfJSSJPFk4DvLhWhYM1.BfmXA32leqCMLcJYPeCmdBK/.:17469:0:99999:7::: user1:!!:17465:0:99999:7::: haha:!!:17469:0:99999:7::: user2:!!:17469:0:99999:7::: user4:!!:17469:0:99999:7::: user8:!!:17469:0:99999:7::: user10:!!:17469:0:99999:7:::
[root@hf-01 ~]# passwd --stdin user10 更改用戶 user10 的密碼 。 hanfeng passwd:全部的身份驗證令牌已經成功更新。 [root@hf-01 ~]# echo "123123" |passwd --stdin user10 這會在shell中常常使用到 更改用戶 user10 的密碼 。 passwd:全部的身份驗證令牌已經成功更新。
[root@hf-01 ~]# echo "123\nsss" 123\nsss [root@hf-01 ~]# echo -e "123\nsss" 123 sss [root@hf-01 ~]# echo -e "123\tsss" 123 sss
[root@hf-01 ~]# echo -e "123456\n123456" |passwd user10 更改用戶 user10 的密碼 。 新的 密碼:無效的密碼: 密碼少於 8 個字符 從新輸入新的 密碼:passwd:全部的身份驗證令牌已經成功更新。 [root@hf-01 ~]# passwd user10 更改用戶 user10 的密碼 。 新的 密碼: 無效的密碼: 密碼少於 8 個字符 從新輸入新的 密碼: passwd:全部的身份驗證令牌已經成功更新。
這裏會發現echo -e "***\n***" |passwd username這裏更改用戶密碼,會比passwd username更改用戶密碼要方便不少,只需一次就可更改爲功
原則:密碼超過十位數起,要包括數字、大小寫字母、特殊符號,這樣才能成爲一個合格的密碼(密碼不能有規律性,不能有本身的姓名、電話等,不然會很容易被猜到)shell