ssh Through Two Hosts in One Command

Say you want a shell on a box but you have to hop through another box to get it.

force@harold:~% ssh admin@maude
maude:~ force$ ssh root@whee
root@whee:~$ echo w00t
w00t

You can do that in one line using -t (pseudo-tty allocation).

force@harold:~% ssh -t admin@maude ssh root@whee
root@whee:~$ echo w00t
w00t

After playing with it, I can only get this to work for one hop. So yes, it’s of limited use. But I hop through another box every time I ssh at work, so I’m going to be getting a lot of mileage out of this little optimization. :)

This entry was posted in quickies and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>