The method of realizing batch key-free login with shell
What this article shares with you is the method of shell to achieve batch key-free login. I believe most people have not yet learned this skill. In order to let you learn, I have summarized the following content for you. Without saying much, let's move on.
Note: ip.txt and send_ssh_key.sh must be in the same root directory
# write server information ip.txt according to the following format for key-free login #-# ipgroup passwordholders 192.168.1.110 VRV 7758521mm 192.168.1.111VOR 7758521VOG 192.168.1.112Rd 7758521pin ssh keyif # generate ssh keyif [!-f "/ root/.ssh/id_rsa"] Then echo "gen ssh key" ssh-keygen-t rsa-b 2048-N'- f / root/.ssh/id_rsafi# checks if expectif is installed! Expect-v & > / ipfor p in $(cat ip.txt | grep-v'#') in the dev/null;then echo "install expect" yum install expect-yfi# loop file Do ip=$ (echo "$p" | cut-F1-d ":") # take out the current IP password=$ (echo "$p" | cut-f2-d ":") # take out the current password # expect interactive process expect-c "spawn ssh-copy-id-I / root/.ssh/id_rsa.pub root@$ip expect {\" * yes/no*\ "{send\" yes\ r\ " Exp_continue}\ "* password*\" {send\ "$password\ r\"; exp_continue}\ "* Password*\" {send\ "$password\ r\";}} "
After reading this article, have you learned the method of batch key-free login with shell? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.