shell腳本--批量分發集羣免密公鑰

使用場景,集羣test01的test用戶,需要免密test集羣的所有服務器。
前提:集羣的test用戶的密碼統一,配置了hosts。

#!/bin/bash
for hostname in  test{01..100}
do
echo $hostname
expect << EOF
   spawn ssh-copy-id -i id_rsa.pub test@$hostname #發送本機公鑰
   expect "*connecting*"
   send "yes\n"
   expect "*password*"
   send "123456\n" #test用戶密碼
   expect eof
EOF
done
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章