sshpass批量修改密码(Batch modify password )

2014-07-09

sshpass命令可以指定ssh登陆密码,当然你也可以用证书实现无密码登录。

下载地址:
http://sourceforge.net/projects/sshpass/
wget --no-check-certificate https://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz/download
安装:
tar zxf sshpass-1.06.tar.gz
cd sshpass-1.06
./configure;make;make install
which sshpass
/usr/local/bin/sshpass

linux批量修改密码实例:

1、利用echo newpasswd|passwd --stdin root
#!/bin/sh
for dst_ip in `cat ip1.txt`;do
echo "Being modified $dst_ip's passwd!"
sshpass -p "oldpasswd" ssh -p322 root@$dst_ip "echo 'newpasswd' | passwd --stdin root"
done

2、利用chpasswd < p.txt
#!/bin/sh
#newpass=`echo "newpasswd"|awk '{print "root:"$1}'`

for dst_ip in `cat ip1.txt`;do
echo "Being modified $dst_ip's passwd!"
sshpass -p "oldpasswd" ssh -p322 root@$dst_ip "echo 'root:newpasswd'|chpasswd;"
done

3、利用openssl passwd -1结合chpasswd -e < p.txt
#!/bin/sh
newpass=`openssl passwd -1 "newpasswd"|awk '{print "root:"$1}'`

for dst_ip in `cat ip1.txt`;do
echo "Being modified $dst_ip's passwd!"
sshpass -p "oldpasswd" ssh -p322 root@$dst_ip "echo '${newpass}'|chpasswd -e;"
done

4、sshpass -p user_password scp -P22 192.168.1.2:/home/test/a.zip .

分类:Linux | 标签: |

相关日志

评论被关闭!