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