安装expect
yum install -y expect
生成公钥
ssh-keygen -t rsa
脚本编写,for循环为什么用不了,so 只能这样写了
[root@www auto]# vim ssh.sh
#!/usr/bin/expect
########无密钥登录
spawn ssh-copy-id root@192.168.22.13 ##spqwn 执行命令
expect "password:" ##提示输入信息
send "hyjrhyj\r" ##输入密码
interact ##回到原状态
spawn ssh-copy-id root@192.168.22.14
expect "password:"
send "hyjrhyj\r"
interact
[root@www auto]# expect ssh.sh