Background: Work on a variety of online machine landing scripts, and some need to log into the board before landing on the machine, and some dynamic password, each input is very troublesome, the use of automated landing scripts to manage too convenient but ~
Principle: Shell call expect to log in remotely
login.sh
#!/usr/bin/env bash
relay_name= "$relay _name"
relay_password= "$relay _password"
relay_host= "xxx"
Token=$1
echo Enter the corresponding number return. "
Select Server in" Server01 "" Server02 "" server03 "does break done
expect-c"
set timeout-1< c11/>puts $server
spawn ssh $relay _name@ $relay _host
set timeout 1
expect-re \ "*password*\" {send \ "$ Password\r\ "}
send \" ssh $server \r\ "
interact
"
Set the script to executable and add it to the environment, and then call it directly.
PS: Set a long connection, just log in once a day
Add the following content to the ~/.ssh/config, if you do not have this file to touch one, the permissions need to 600 before it can take effect
Host *
controlpersist yes
controlmaster auto
controlpath ~/.ssh/master-%r@%h:%p
Compression Yes