Linux Batch Build trust relationship, implementation of SSH without password login script

Source: Internet
Author: User

Role:

Copy the SSH public key of the current machine to another machine to enable SSH login to other machines from the current machine without password.

How to use:

1) Write the IP address you want to add to a file, such as host

2) Save the script as sh file, such as Install_ssh.sh set executable permissions

3) rewrite the password settings in the script, currently only support a fixed number of passwords.

4) Execute 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

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux Batch Build trust relationship, implementation of SSH without password login 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.