批量分发公钥

#!/usr/bin/expect
set timeout 10
set username [lindex $argv 0]
set password [lindex $argv 1]
set hostname [lindex $argv 2]

spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $username@$hostname

expect {
            "Are you sure you want to continue connecting (yes/no)?" {
            send "yes\r"
            expect "password:"
            send "$password\r"
            }
            "password:" {
            send "$password\r"
            }
            "Now try logging into the machine" {
            }
        }
expect eof
user="root"
passwd="xxxx"

for i in `seq 34 41`; do
ip="xxx.xxx.xxx.$i"
/etc/ansible/inventory/copy-ssh.exp $user $passwd $ip
done

 

posted @ 2018-04-19 15:41  一米八大高个儿  阅读(236)  评论(0编辑  收藏  举报