ssh互信
```shell
#!/bin/bash
cat > ip.txt <<EOF
10.1.128.85:rootroot
10.1.128.86:rootroot
10.1.128.87:rootroot
EOF
# 安装 expect
echo 'Install expect .... '
[ -f /usr/bin/expect ] || yum -y install expect >/dev/null
#注意 || 和 &&两种用法
[ ! -f /root/.ssh/id_rsa ] && ssh-keygen -P '' -f /root/.ssh/id_rsa
tr ':' ' ' < ip.txt|while read ip pass
do
ping -c1 $ip &>/dev/null
if [ $? -eq 0 ];then
expect -c "
set timeout 60;
spawn ssh-copy-id root@$ip;
expect {
\"password\" { send \"$pass\r\" }
\"yes/no\" { send \"yes\r\"; exp_continue }
} ;
expect eof
"
fi
done
```
---

```
#!/bin/bash
ips="
192.168.111.128
192.168.111.129
192.168.111.131
"
export SSHPASS=rootroot
if [ -f /usr/bin/sshpass ] || yum -y install sshpass ;then
[ ! -f /root/.ssh/id_rsa ] && ssh-keygen -P '' -f /root/.ssh/id_rsa
for ip in $ips;
do
{
sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $ip ;
} &
done
wait
else
echo "请安装sshpass"
exit
fi
```