利用expect实现linux第一次互信
免密之后第一次相互通信
#!/bin/bash
#set -x
passwd=password
# create ip konwn_hosts
user_ips=$(cat /etc/hosts|sed \1\,\2\d )
#user_ips=$(cat /ddhome/usr/tools/hosts|sed \1\,\2\d )
for user_ip in ${user_ips[@]}
do
expect -c " set timeout 2;
spawn ssh root@${user_ip}
expect {
\"(yes/no)\" { send \"yes\r\";exp_continue }
}
expect \"]#\"
send \"exit\n\"
expect eof
";
done
复制公钥
#!/bin/bash
#create copy
host="ip."
for((i=2;i<22;i++))
do
echo ${host}${i}
scp /root/.ssh/authorized_keys root@${host}${i}:/root/.ssh/
scp /etc/hosts root@${host}${i}:/etc
scp /root/.ssh/known_hosts root@${host}${i}:/root/.ssh/
done
浙公网安备 33010602011771号