Possible Duplicate:
Multiple hops SSH tunnel…
Here's the setup:
desktop: my desktop. I have root and can do anything I want. Kubuntu 10.04.
bastion: a bastion host that only allows inbound SSH connections on port 22. I do not control this server. I cannot write files anywhere on this server. The only commands available to me are ssh
and shell (bash) builtins. CentOS.
server: a server with a file on it that I want to retrieve (i.e. copy to desktop). Only allows incoming SSH connections from bastion. Does not allow outgoing ssh connections. CentOS.
I can ssh from desktop to bastion, and then ssh from bastion to server. I can set up an SSH tunnel on B as follows:
ssh -fNL 30000:localhost:22 server
And then the following allows me to connect to server from bastion:
bastion % ssh localhost -p 30000
But this does not work (bastion refuses the connection):
desktop % ssh bastion -p 30000
I'm wondering if there's some way I can turn an ssh session from desktop to bastion into a tunnel that connects to port 30000 locally on bastion, so that I can then go through that connection to get to server. If bastion allowed incoming connections on high ports, I could do it, but it doesn't, only port 22.
I know that there's other options: I could cat the target file to my screen and save it out locally, but this is a hack (and annoying if there's binary data in the file).
EDIT: I figured out one stupid solution:
bastion % ssh server "cat filename1" | ssh localhost "cat > filename2"
This works, although the ssh prompts (are you sure you want to connect, yes/no? and the password) get in each others' way so you have to type "yes" and the various host passwords in the correct order). But it would be nice if I could tunnel through to server from desktop.