Script Automatic Login shell script (compact version)

Source: Internet
Author: User
Tags compact

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
Related Article

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.