批量推送密钥

首先执行产生密钥操作

#################批量推公钥##################
#!/bin/bash
#abel
>ip.txt
>/root/.ssh/known_hosts

if [ ! -f ~/.ssh/id_rsa.pub ];then
ssh-keygen -P "" -f ~/.ssh/id_rsa
exit
fi
yum -y install expect


for i in {2..254}
do
{
ip=192.168.122.$i
ping -c1 -W1 $ip &>/dev/null
if [ $? -eq 0 ];then
echo $ip >> ip.txt
/usr/bin/expect <<-EOF
set timeout 10
spawn ssh-copy-id -i $ip
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "centos\r" }
}

expect "#"
send "exit\r"
expect eof
EOF
fi
}&
done


wait
echo "finish...."
---------------------
作者:abel_dwh
来源:CSDN
原文:https://blog.csdn.net/abel_dwh/article/details/78468007
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-04-03 17:39  大小狮子  阅读(223)  评论(0编辑  收藏  举报