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