Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way, in a single command, to establish a ssh connection from my computer A, through computer B, to computer C, such that I have access to the shell on computer C?

A wrinkle (which seems to rule out simply forwarding the ssh connection using the -L option) is that I have the password to the account on computer B, and the account on computer B is authorized to connect to the account on computer C, but I do not have the password to the account on computer C.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

I understood that you want just to log in to the computer C, not really tunnel anything from A to C. So, this should do the trick:

ssh -t computer-b "ssh computer-c"

You might have to enter passwords twice, first for computer B and then for computer C, but this can be avoided by using ssh's key-pair authentication.

share|improve this answer
1  
Thanks - it works! If I may be so-bold as to ask a follow-up. Any ideas how I can scp a file from A to C in a single command? –  sanity Aug 25 '09 at 13:35
    
That's a bit tricky. It could be done by adding tar to the mix, but if it's only one file and computer B has the disk space to hold it for a while, it's a lot easier to copy it in two steps. –  af. Aug 25 '09 at 13:40
    
You can also do this three times! ssh -t computer-b "ssh -t computer-c 'ssh computer-d'" :D –  Gerald Kaszuba Aug 1 '13 at 2:06

You probably want to use SSH's ProxyCommand: http://benno.id.au/blog/2006/06/08/ssh%5Fproxy%5Fcommand

share|improve this answer
    
I can't find a way to make this work because I don't have the password for computer C, and this approach seems to require it. Open to suggestions though as this approach does seem more elegant. –  sanity Aug 25 '09 at 14:05

If you're using ssh keys, you could generate a new key for machine B and use that to connection from A to B. On machine B, you can add

command="ssh C" ssh-....

in the ~/.ssh/authorized_keys file. That means that whenever you connect to B with that ssh key, it will execute the ssh C command.

I don't know if this works with scp.

share|improve this answer

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.