scp批量上传公钥
scp批量上传公钥
scp批量上传公钥
#!/bin/bash
cat /root/.ssh/id_rsa.pub >> /root.ssh/authorized_keys 将公钥导到auth文件中去
host1=`cat /root/a` ##a文件里的内容是你想要scp公钥的目标主机地址
for i in $host1; do
command1="scp /root/.ssh/authorized_keys $i:/root/.ssh/authorized_keys"
expect -c "
set timeout 60;
spawn $command1;
expect {
\"(yes/no)?\" {send \"yes\r\"; exp_continue}
\"$i's password:\" {send \"leezqang\r\"; exp_continue} ## send 是密码 这种方法有个限制就是所有目标主机密码需要一致
如果密码不一致 可以定义数组来完成这个功能 }
"
done
www.2cto.com
评论暂时关闭