歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> scp批量上傳公鑰

scp批量上傳公鑰

日期:2017/3/1 16:56:14   编辑:關於Linux
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
Copyright © Linux教程網 All Rights Reserved