集群SSH免密登录脚本
#!/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 dsa
expect ":" {send "\n;"}
#expect "exists" {send "y;"}
expect ":" {send "\n;"}
expect ":" {send "\n;"}
expect eof
EOF
fi
for i in 29 86 80 91 211 73 71 205 24 145 82 96 93 176 165 152
do
/usr/bin/expect <<EOF
spawn ssh-copy-id root@192.168.224.$i
expect "yes/no" {send "yes\n;exp_continue"}
expect "password" {send "r00tme321\n;"}
expect eof
EOF
done
- for i in 29 86 80 91 211 73 71 205 24 145 82 96 93 176 165 152
将数字改成实际的ip地址 - spawn ssh-copy-id root@192.168.224.$i
修改需要的用户名,要做哪个用户免密就用哪个username - expect “password” {send “r00tme321\n;”}
修改对应username的password