bash copy-id.sh 就可以了。 没有安装expect的 yum install expect
1 2 3 | cat host 192.168.0.11:passwd11 192.168.0.12:passwd12 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | cat copy- id .sh #!/bin/bash cat ~ /host | while read line do echo $line PS=${line #*:} IP=${line%:*} expect <<-EOF spawn ssh -copy- id $IP puts $PS expect { "*yes/no" { send "yes\r" ; exp_continue } "*password:" { send "$PS\r" } } expect "*Number*" expect eof EOF done |