配置主机互信的shell脚本
使用注意事项 格式
#bash huxin.sh 主机密码 IP地址
将下面内容保存为 huxin.sh (文件名可以自取)IP地址最好为一个文件里面保存上要配置互信的ip
yum源里要有expect
#!/bin/bash
cd ~
passwd=$1
yum install -y expect
/usr/bin/expect <<EOF
spawn ssh-keygen
expect "(/root/.ssh/id_dsa):"
send "\r"
expect "(empty for no passphrase):"
send "\r"
expect "again:"
send "\r"
expect "Overwrite"
send "y\r"
expect "again:"
send "\r"
expect eof
exit
EOF
cat /root/.ssh/id_rsa.pub>> /root/.ssh/authorized_keys
chmod 644 /root/.ssh/authorized_keys
chmod 755 /root/.ssh
a=$2
for ip in $a
do
/usr/bin/expect << EOF
spawn scp -r /root/.ssh/ root@$ip:/root/
expect "continue connecting (yes/no)?"
send "yes\r"
expect "password:"
send "$passwd\r"
expect "password:"
send "$passwd\r"
expect eof
exit
EOF
done