##### Bulk Deployment SSH private key authentication #####
First, install expect, direct Yum can
Second, bulk deploy SSH private key script
batch_sshkey.sh
==============================================================
#!/bin/bash
Cd/root
Cat/root/.ssh/id_rsa.pub >/root/.ssh/authorized_keys
For i in ' Cat ip.txt '
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
============================================================
Ip.txt (front is IP, followed by password, colon: Split)
192.168.8.23:123456
192.168.8.24:456789
============================================================
remote_operate.sh
#!/bin/bash
if [!-d/root/.ssh];then
Mkdir/root/.ssh
Fi
cp/tmp/authorized_keys/root/.ssh/
==========================================================
You can run batch_sshkey.sh.
batch_sshkey.sh Set executable permissions, required./execute, do not need to press ENTER during execution, the deployment will be completed automatically.
Linux bulk deployment without key script