Build trust relationships in batches in Linux to implement ssh password-less login scripts

Source: Internet
Author: User

Build trust relationships in batches in Linux to implement ssh password-less login scripts

Purpose:

Copy the ssh public key of the current machine to another machine, so that you can log on to another machine through ssh without a password.

Usage:

1) write the IP address to be added to a file, such as host

2) Save the script as a sh file, for example, install_ssh.sh.

3) rewrite the password settings in the script. Currently, only several passwords can be fixed.

4) execute the command

Sh install_ssh.sh

Code:

#! /Bin/shauto_ssh_copy_id () {local HOST = $1 local PASSWD = $2 expect CT-c "set timeout-1; spawn ssh-copy-id root @ $ HOSTexpect {* 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 = 'nosafenowork @ 2014 'passwd2 = 'safety First @ 426' passwd3 = 'ddd @ 2008 'passwd4 = '000000' passwd5 = 'asdasd' passwd6 = '000000' while Read line; doecho "$ line"> & 2 isSucceed = 'false' for pw in $ passwd1 $ passwd2 $ passwd3 $ passwd4 $ passwd5 $ passwd6doif auto_ssh_copy_id "$ line" $ response = 'true' break; fidoneif [$ isSucceed! = 'True']; thenecho 'notsucc' $ linefidone

 

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.