批量部署ssh私钥

#!/bin/bash  
# auto copy publick key to ssh server,but you must create the rsa public key first!   
# include a  expect expect script 
# see the log file  /tmp/test.log 
# see the failure log file /tmp/down.log
#批量部署ssh私钥,密码相同"westos"
#安装expect包
if
  rpm -q expect
  then
   echo "good" >/dev/null
else
   echo "you must install the expect package"
fi
    
cat > /tmp/auto.tcl << end
#!/usr/bin/expect -f 
set timeout 5 
#set user [lrange $argv 1 1] 
#set password [lrange $argv 2 2] 
set ipaddr [lrange \$argv 0 0] 
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@\$ipaddr 
expect  "Are you sure you want to continue connecting (yes/no)?" 
send "yes\r"
expect "*?assword:" 
send "westos\r" 
expect end
end

#!/bin/bash
chmod 755 /tmp/auto.tcl
rm -f /root/.ssh/known_hosts
for i in {46,56,66}
do
if
ping -c2 192.168.0.$i &>/dev/null
then
/tmp/auto.tcl 192.168.0.$i &>/dev/null
echo "********192.168.0.$i**************">>/tmp/test.log
ssh 192.168.0.$i ifconfig eth0|grep 'inet addr:'|cut -f2 -d:|cut -f1 -d' ' >>/tmp/test.log
else
echo "the server 192.168.0.$i is't exsit">>/tmp/down.log
fi
done

转载于:https://my.oschina.net/sharelinux/blog/116578

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值