Do not enter a username password to log on to the online Linux machine via a springboard machine

Source: Internet
Author: User

Questions:

In general, the company all the servers in the intranet, public network access, Management Server must first by logging on to a springboard machine, and then by the springboard machine login to the corresponding server to operate, the springboard machine and the server connection is the intranet address. We often see the phenomenon is this, each time to login through SSH two times, enter two passwords, passwords are often wrong, patience.

Prerequisites:

Mac or other Unix-like operating system as a local machine, install expect

Workaround:

Automatic interaction with the server using expect's auto-interaction feature

1#!/usr/bin/expect2#author1031294046@qq. com3 4 #定义数组, more than one is defined here5 #连接枚举6Set Connection_enum (1)"first target machine alias"#名字可以随便取7Set Connection_enum (2)"second target machine alias"8 9 #用户枚举TenSet Connection_user (1)"first target machine user name" OneSet Connection_user (2)"second target machine user name" A  - #连接密码 -Set CONNECTION_PASSWD (1)"first target machine password" theSet CONNECTION_PASSWD (2)"second target machine password" -  - #连接ip, here is the general springboard machine with the target machine SSH connection is to go intranet, so the configuration is the intranet IP -Set CONNECTION_IP (1)"first target machine IP" +Set CONNECTION_IP (2)"second target machine IP" -  + #函数定义必须在使用前面否则会报错 A #列出可用的host以及枚举 at proc Connectionlist {} { - Global Connection_enum #函数里面如果要用全局变量expect语法里要global进来 - #[array size Connection_enum] command is to find the length of the array connection_enum -      for{Set I1} {$i <=[array size Connection_enum]} {INCR i} {#这是expect语法的for循环和自增 -Puts"signin \[$i \] for $connection _enum ($i)"#输出到控制台 -     } in } -  to #登录host + proc Connecthost {enum} { - Global CONNECTION_PASSWD the Global Connection_ip * Global Connection_user $ Panax Notoginseng #我这里登录跳板机是免密的, so comment out the following three lines, if it is not a secret login the board needs to open the note -SpawnSSH-L Springboard Machine user nameSpringboard Machine IP the #expect { +#"*password*"{Send"Login to the springboard password\ r" } A     #       } the  + #接收到跳板机登录成功的消息后登录目标机器, this line of expect content is not the same as mine, according to the information returned by the Springboard machine to match -Expect"*system Restart required*"{Send"ssh-l $connection _user ($enum) $connection _ip ($enum) \ r"} $ Expect { $             "yes/no"{Send"yes\r"; exp_continue;} -             "*password:*"{Send"$connection _passwd ($enum) \ r" } -            } the Interact - }Wuyi  the if{[Llength $argv] = =0} { -Puts"Choice your Login host:" Wu connectionlist -  About Expect { $ #正则匹配输入的值, 1 or 2 -         "\[12\]" { - Set num $expect _out (buffer); # $expect _out (buffer) to get input values, set for type conversion - connecthost $num; A         } +#"1"{Connecthost1 } the#"2"{Connecthost2 } -     } $}

You can run the script directly after modifying the file based on your individual and its configuration.

Do not enter a username password to log on to the online Linux machine via a springboard machine

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.