Shell keyless script

Source: Internet
Author: User

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.

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.