0

At my company, In order to SSH into anything, I first have to SSH into an intermediary server like so:

(me@local.machine) ssh intermediary.server.com

(me@intermediary.server.com) ssh application.server.com

(root@application.server.com) this is the command prompt I want to be at

I would like to make a bash alias, so that I can run a single command on my local machine and get dropped into the desired machine's "command prompt".

Is this possible?

  • Do you have netcat or nc installed on the bastion host? – D_Bye Jan 19 '15 at 17:54
  • 2
    You can use the ProxyCommand in your local ~/.ssh/config to hop to remote from intermediary: Host remote\n ProxyCommand ssh -W %h:%p intermediary – jasonwryan Jan 19 '15 at 17:59
  • See http://unix.stackexchange.com/questions/82269/ssh-tunnel-through-middleman-server-how-to-connect-in-one-step-using-key-pair regarding using netcat on the intermediary server. – Lars Rohrbach Jan 19 '15 at 18:06

1 Answers1

1

I think this is what you want, in your .bashrc or .bash_profile

alias cmdname="ssh -t me@intermediary.server.com ssh application.server.com"

From man ssh:

  -t     Force pseudo-tty allocation.  This can be used to execute arbi-
         trary screen-based programs on a remote machine, which can be
         very useful, e.g., when implementing menu services.  Multiple -t
         options force tty allocation, even if ssh has no local tty.

Source the file to pickup the new alias:

source .bashrc [OR] source .bash_profile

Test it out now from terminal:

[user]# cmdname

If you don't already I would also setup ssh-keys so that you don't need to enter any passwords. You just enter the command and are auto-logged in.

devnull
  • 5,431