#!/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 root@10.0.0.$i
expect "yes/no" {send "yes\n";exp_continue}
expect "password" {send "123456\n"}
expect eof
EOF
done
#注意输入ip的时候要用空格隔开
ssh免密交互批量部署
最新推荐文章于 2024-11-09 23:14:47 发布