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

#注意輸入ip的時候要用空格隔開
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章