码迷,mamicode.com
首页 > 其他好文 > 详细

批量部署ssh私钥认证

时间:2015-11-12 13:27:17      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:

vim  batch_sshkey.sh

#!/bin/bash
cd /root
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
for i in `cat iplist`
do
ip=$(echo "$i"|cut -f1 -d":")
password=$(echo "$i"|cut -f2 -d":")
expect -c "
spawn scp /root/.ssh/authorized_keys /root/remote_operate.sh root@$ip:/tmp/
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$password\r\"; exp_continue}
\"*Password*\" {send \"$password\r\";}
}
"

expect -c "
spawn ssh root@$ip "/tmp/remote_operate.sh"
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$password\r\"; exp_continue}
\"*Password*\" {send \"$password\r\";}
}
"
done

============================================================

vim  iplist前面是IP,后面是密码,用冒号:分割

192.168.8.23:123456
192.168.8.24:456789

============================================================

 vim remote_operate.sh

#!/bin/bash
if [ ! -d /root/.ssh ];then
mkdir /root/.ssh
fi
cp /tmp/authorized_keys /root/.ssh/
rm -f /tmp/authorized_keys
rm -f $0

==========================================================

运行batch_sshkey.sh后即可实现批量部署。

 

批量部署ssh私钥认证

标签:

原文地址:http://www.cnblogs.com/wjoyxt/p/4958593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!