0

This question already has an answer here:

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?

marked as duplicate by Gilles 'SO- stop being evil' bash Jan 19 '15 at 18:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 unix.stackexchange.com/questions/82269/… regarding using netcat on the intermediary server. – Lars Rohrbach Jan 19 '15 at 18:06
0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.