vim aa.sh
``
#!/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 “:” {send “\n;”}
expect “:” {send “\n;”}
expect “:” {send “\n;”}
expect eof
EOF
fi
read -ep “输入需要免密的IP,可以输入多个,用空格隔开:” IP
for i in KaTeX parse error: Expected 'EOF', got '#' at position 5: IP #̲循环你免密的IP do /us…i
expect “yes/no” {send “yes\n;exp_continue”}
expect “password” {send “123456\n;”}
expect eof
EOF
done
sh aa.sh
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191109100436342.png)