[root@bre01 opt]# cat env.csv
ip passwd hostname
192.168.248.129 123123 bre01
192.168.248.130 123123 bre02
[root@bre01 opt]# cat env.sh
#!/bin/bash
function RSA(){
echo "设置主机公钥" >> ./install_init.log
rpm -qa |grep expect
if [ $? -eq 0 ]
then
echo "already install expect"
else
yum install expect wget -y
fi
ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa
}
function ADD_RSA(){
echo "设置主机互信" >> ./install_init.log
for ip in `cat ./env.csv |awk 'NR >1{print $1}'`;do
password=`cat ./env.csv |grep $ip |awk '{print $2}'`
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$ip
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$password\r\"; exp_continue}
\"*Password*\" {send \"$password\r\";}
}
"> rsa.log
done
}
RSA
ADD_RSA
标签:ip,rsa,expect,env,linux,服务器,password,root,互信
From: https://www.cnblogs.com/sddll/p/18080012