Linux bulk deployment without key script

Source: Internet
Author: User

##### 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.