Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Common multiple SSH connections file handling issue

I used to do something like that often:

home $> ssh user@server1
user@server1's password:
server1 $> ssh user@server2
user@server2's password:
server2 $>

Server2 is available from server1 only, so I have to do stuff like that all time.

So, question is. How can I do 2 consecutive logins in one command?

home $> ssh_many user@server1 user@server2
user@server1's password:
user@server2's password:
server2 $>
share|improve this question

marked as duplicate by Gilles, Michael Mrozek May 11 '11 at 21:03

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.

up vote 5 down vote accepted

Try using the ssh -t argument.

ssh -t user@server1 ssh user@server2

From the man ssh page:

    -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.

This should give you what you are after.

share|improve this answer

You are probably more interested in a way to directly access server2 from home. There's a simple solution to use your connection form home to server1 to create a tunnel that will allow you directly ssh to server2 from home. You can then also do other protocols like SFTP or Rsync over SSH straight between the two. As Gilles suggested, look at Common multiple SSH connections file handling issue

share|improve this answer

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