Shell keyless script
##### Batch deploy ssh Private Key Authentication #####
1. First install unzip CT and directly use yum.
Ii. Batch deploy the 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 ":")
CT-c"
Spawn scp/root/. ssh/authorized_keys/root/remote_operate.sh root @ $ ip:/tmp/
CT {
\ "* Yes/no * \" {send \ "yes \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \";}
}
"
CT-c"
Spawn ssh root @ $ ip "/tmp/remote_operate.sh"
CT {
\ "* Yes/no * \" {send \ "yes \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \"; exp_continue}
\ "* Password * \" {send \ "$ password \ r \";}
}
"
Done
========================================================== ================================
Ip.txt (the front is IP address, followed by password, separated by a colon)
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/
========================================================== ============================
Run batch_sshkey.sh.
Batch_sshkey.sh sets the executable permission, which must be executed./. During execution, you do not need to press enter to automatically complete the deployment.