bash copy-id.sh 就可以了。 没有安装expect的 yum install expect
cat host 192.168.0.11:passwd11 192.168.0.12:passwd12
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