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.

link|improve this question

36% accept rate
feedback

3 Answers

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.

link|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
feedback

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

link|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
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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