通过脚本更新Centos密码命令

作者: 管理员 分类: 系统运维 发布时间: 2021-07-20 18:54

–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 用户名

[root@localhost ~]# passwd --stdin root   为root用户设置密码。
Changing password for user root.
123456
passwd: all authentication tokens updated successfully.
[root@localhost ~]# echo "123456"
123456
[root@localhost ~]# echo "123456" | passwd --stdin root  把echo返回的字符qwert设置为用户root的密码
Changing password for user root.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# 

#脚本写法:
echo "123456" |passwd --stdin root'

这种方式虽然简单,但是通过history命令可以查到用户的密码,所以不安全,所以在脚本的最后需要有清除history记录的命令执行。

清除history记录:history -c


发表评论

电子邮件地址不会被公开。