Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

To get to my machine in my office, at the moment I am doing this:

me@home:~$ ssh unix.university.com
me@unix:~$ ssh unix.department.univeristy.com
me@unix.department:~$ ssh office-machine.department.university.com
me@office-machine:~$ echo "This is very annoying"

Is there an easy way of automating this process, perhaps a single command that I can use at my end?

share|improve this question

3 Answers 3

up vote 16 down vote accepted

You can use the ssh client to execute ssh on the remote machine upon login.

ssh -t unix.university.com \
    ssh -t unix.department.univeristy.com \
    ssh -t office-machine.department.university.com

(The reason I include -t in the invocations is because ssh was giving me errors re: stdin not being a terminal when I tried it on my own machine; your machine may be different.)

When you exit from the last shell, the process will chain-exit, saving you typing Ctrl-D over and over again.

share|improve this answer
    
perfect, thanks –  Lucas Nov 21 '11 at 2:58

SSH tunneling. I don't recall exactly how to do this however I know there's a way to basically have a machine allow a tunnel by perhaps connecting to a separate port. That way you just shell to the same initial machine (with a different port for example) and it will plop you on your final location.

Would have to look up how to configure it though.

:)

share|improve this answer
    
You don't want (and probably you can't) open a port or your university ssh gateway… –  Stéphane Gimenez Nov 24 '11 at 23:34
3  
If you don't know how to do it, and can't be bothered to look it up, why did you post this answer? –  amphetamachine Nov 28 '11 at 8:32
    
Not really an answer –  gabe. Dec 5 '11 at 23:24

Yes, there is a great way to do that using ssh ProxyCommand and netcat

Put something like this in your .ssh/config

Host *.department.university.com
User me
ForwardAgent yes
ProxyCommand ssh unix.university.com nc %h %p

This will log directly into any .department.university.com server using the jump/bastion host unix.university.com. You may also need a stanza for unix.university.com directly.

Here is a link explaining how it works: http://backdrift.org/transparent-proxy-with-ssh

With this technique, you can now just write

ssh unix.department.university.com

and it will all appear direct. Tools like rsync, scp, etc (anything in the ssh stack) will work transparently, as well.

share|improve this answer
1  
+1 I use something similar to this to push data from a test network to a prod network through a staging server. –  Arcege Nov 21 '11 at 23:20
1  
Yup, this works great! –  gabe. Nov 24 '11 at 19:05
3  
Just for the record newer versions of ssh support the -W option, you can do something like ProxyCommand ssh -W %h:%p gateway instead of depending on nc –  Ulrich Dangel Jun 24 '12 at 23:38
    
Good to know! Thx –  Aaron Brown Jun 24 '12 at 23:39
    
works great if the name of the user is the same across machines; if it is different you have to do something like ProxyCommand ssh -W %h:%p user@gateway –  Riccardo Cossu Jun 12 '13 at 14:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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