Vim batch_sshkey.sh
#!/bin/bash
Cd/root
Cat/root/.ssh/id_rsa.pub >/root/.ssh/authorized_keys
For i in ' Cat iplist'
Do
Ip=$ (echo "$i" |cut-f1-d ":")
Password=$ (echo "$i" |cut-f2-d ":")
Expect-c "
Spawn scp/root/.ssh/authorized_keys/root/remote_operate.sh [email protected] $ip:/tmp/
Expect {
\ "*yes/no*\" {send \ "yes\r\"; Exp_continue}
\ "*password*\" {send \ "$password \r\"; Exp_continue}
\ "*password*\" {send \ "$password \r\";}
}
"
Expect-c "
Spawn ssh [email protected] $ip "/tmp/remote_operate.sh"
Expect {
\ "*yes/no*\" {send \ "yes\r\"; Exp_continue}
\ "*password*\" {send \ "$password \r\"; Exp_continue}
\ "*password*\" {send \ "$password \r\";}
}
"
Done
============================================================
Vim iplist( front IP, followed by password, colon: Split )
192.168.8.23:123456
192.168.8.24:456789
============================================================
Vim remote_operate.sh
#!/bin/bash
if [!-d/root/.ssh];then
Mkdir/root/.ssh
Fi
cp/tmp/authorized_keys/root/.ssh/
Rm-f/tmp/authorized_keys
Rm-f
==========================================================
You can implement a batch deployment after you run batch_sshkey.sh.
Bulk deploy SSH private key authentication