Linux Batch Build trust relationship, implement SSH no password landing script

Source: Internet
Author: User

Role:

Copy the SSH public key of the current machine to another machine. In order to realize from the current machine can ssh without password landing to other machines

Usage:

1) Write the IP address you want to add to a file. For example, host

2) Save the script as an SH file, such as Install_ssh.sh set the operational permissions

3) rewrite the password settings in the script. Only a few password are supported at the moment.

4) Run the command

SH install_ssh.sh


Code:


#!/bin/sh


auto_ssh_copy_id () {
Local host=$1
Local passwd=$2
Expect-c "Set timeout-1;
Spawn Ssh-copy-id [email protected] $HOST
Expect {
*publickey* {exit 1;}
* (yes/no) * {send yes\r; exp_continue;}
*password* {send \ "$PASSWD \r\"; exp_continue;}
* * {send \ "$PASSWD \r\"; exp_continue;}
}";
}


#eof {exit 0;}
passwd1= ' [email protected] '
passwd2= ' [email protected] '
passwd3= ' [email protected] '
passwd4= ' 123456 '
passwd5= ' ASDASD '
passwd6= ' 12345 '
while read line; Do
echo "$line" >&2
Issucceed= ' FALSE '
For PW in $passwd 1 $passwd 2 $passwd 3 $passwd 4 $passwd 5 $passwd 6
Do
If auto_ssh_copy_id "$line" $PW
Then
Issucceed= ' TRUE '
Break
Fi
Done


if [$isSucceed! = ' TRUE ']; Then
Echo ' NOTSUCC ' $line
Fi
Done

Linux Batch Build trust relationship, implement SSH no password landing 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.