linux自动分发秘钥到每台主机
一、需要安装expect软件
# yum install expect -y
二、执行脚本+IP地址将秘钥分发到指定主机上
# cat add_host.sh #!/usr/bin/expect set ip [lindex $argv 0] set password Admin@9009 spawn ssh-copy-id -i /home/admin/.ssh/id_rsa.pub admin@${ip} expect { "(yes/no)" { send "yes\n"; exp_continue } "Password:" { send "$password\n" } } interact # sh add_host.sh 192.168.0.6