linux --stdin 管道輸出
--stdin
This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.
這個選項用於從標准輸入管道讀入新的密碼。
使用 echo 方式來重置Linux 系統用戶密碼:
echo “新密碼”|passwd --stdin 用戶名
1
2
3
4
5
6
7
8
9
10
[root@rhel7 ~]# passwd --stdin rusky 為rusky用戶設置密碼。
Changing password for user rusky.
zxcvbnm
passwd: all authentication tokens updated successfully.
[root@rhel7 ~]# echo "qwert"
qwert
[root@rhel7 ~]# echo "qwert" | passwd --stdin rusky 把echo返回的字符qwert設置為用戶rusky的密碼
Changing password for user rusky.
passwd: all authentication tokens updated successfully.
[root@rhel7 ~]#
這種方式雖然簡單,但是通過history命令可以查到用戶的密碼,所以不安全。