使用場景,集羣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