ssh免密交互批量部署

#!/bin/bash
yum -y install expect
if [ -f /root/.ssh/id_rsa ]||[ -f id_rsa.pub ];then #判断是否有公密钥
  continue
else
/usr/bin/expect<<EOF
spawn ssh-keygen -t rsa 
expect "(/root/.ssh/id_rsa):" {send "\n"}
expect "(empty for no passphrase):" {send "\n"}
expect "Enter same passphrase again:" {send "\n"}
expect eof
EOF
fi
read -ep "请输入需要免密的IP:" IP
for i in $IP
do
/usr/bin/expect<<EOF
spawn ssh-copy-id [email protected].$i
expect "yes/no" {send "yes\n";exp_continue}
expect "password" {send "123456\n"}
expect eof
EOF
done
发布了35 篇原创文章 · 获赞 11 · 访问量 2964

猜你喜欢

转载自blog.csdn.net/weixin_45697805/article/details/103069220
今日推荐