0
点赞
收藏
分享

微信扫一扫

Linux命令:chpasswd

批量或者单一修改用户密码

语法:

1:# echo 用户名:密码 | chpasswd

2:# chpasswd < test.txt

实例

1、直接修改test用户的密码为hello#2022

echo test:hellow#2022 |chpasswd

2、使用test.txt里面的用户名密码批量修改相应用户的密码

2.1:首先建立指令文件doiido.txt(格式为[username:passwd])

vi test.txt
test1:helloboy
test2:hellogirl

2.2:将test.txt的内容传输到chpasswd指令来修改相应用户的密码

chpasswd < test.txt

3、让普通用户使用chpasswd

默认普通用户是没有chpasswd的权限,但是可以通过修改命令文件权限来修改

chmod 4755 /usr/sbin/chpasswd

注意事项

1:用户名必须是系统上已存在的用户

2:普通用户没有使用这个指令的权限

3:如果输入文件是按非加密方式传递的话,请对该文件进行适当的加密。

4:指令文件不能有空行

Linux命令:chpasswd

直接修改用户密码

语法:

echo “新密码”|passwd --stdin 用户名

–stdin 这个选项用于从标准输入管道读入新的密码。

使用 echo 方式来重置Linux 系统用户密码:

echo “新密码”|passwd --stdin 用户名
方法一:
[root@rhel~]# passwd --stdin test 为tst用户设置密码。
Changing password for user test.
zxcvbnm
passwd: all authentication tokens updated successfully.
[root@rhel~]# echo "qwert"
qwert

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

这种方式虽然简单,但是通过history命令可以查到用户的密码,所以不安全。

举报

相关推荐

0 条评论