Logging in to another a remote server using SSH
Use Case:
(1) SSH in to one server and login with username and password using expect (2) Once logged in, login to another server using another username and password via expect I tried the below script but does not work #!/bin/bash SERVER1=1.1.1.1 SERVER2=2.2.2.2 /usr/bin/expect <<EOD set timeout 1000000 spawn ssh $CLIENT_ID@$SERVER1 expect *$* send "ssh $CLIENT_ID@$SERVER2\r" expect "assword:" send "Pass123\r" interact EOD Can this be done? |
Yes, it can be done.
That is not the way I would do it. Have you considered setting up keys for password-free authentication, and simply doing something like Code:
ssh guy1@1.1.1.1 "ssh guy2@2.2.2.2" |
Quote:
Laziness is a virtue in a sysadmin :D |
Quote:
Taking it a step further, you can put your options in ~/.ssh/config and then just type ssh server2 as a shortcut to get to server2 via server1: Code:
Host server1 |
Thanks for your replies. I have initially tried the one suggested by @vwpeckham but it does not work for me.
$ ssh username@server1 'ssh username@server2' Pseudo-terminal will not be allocated because stdin is not a terminal. Authenticated with partial success. Permission denied, please try again. Permission denied, please try again. Permission denied (password). $ I do not have access to root for either server1 and server2 so I cannot modify any config. Server1 and Server2 doesn't also have expect there so this is triggered mainly on the client. |
Quote:
Quote:
At this point, I would highly recommend skimming through the manual page for ssh_config and ssh on your own computer so that you are familiar with the options your version has. Code:
man ssh_config |
@Turbocapitalist, This works like a charm. You're the man!!
|
No worries.
If you don't want to type more than ssh server1 server2 each time, then you can put the equivalent of -t into your SSH client configuration ( ~/.ssh/config ) up near the top: Code:
Host server1 |
All times are GMT -5. The time now is 03:43 AM. |