SSH back to the local machine from a remote SSH session

sshssh-tunnel

I'm trying to do something rather unusual (for me anyway) with SSH and I can't get it to work, hopefully you can help.

I want to establish a connection to a remote server from my Mac using SSH. So far so good.
Now the tricky bit, with the connection to the remote server established I want to then initiate a connection from the remote server BACK to the local machine. I know, crazy. Basically I need to jump through these hoops to be able to browse the remote server and then send file information back to my local machine so it can be dealt with by an application on the local machine. Hopefully that makes sense!

At the moment if I SSH back to the local machine once I am logged in to the remote server, the terminal will just sit there whirring away, no errors even with -v.

I am trying to discover where I should be calling by looking at the output of the $SSH_CLIENT variable, but I'm on a standard vanilla internet connection (no static ip address) I think this might be what is causing the problem.

Things I have established:
I'm on a Mac(OS X 10.6.4) and I have Remote Login enabled in system preferences/sharing
If I try and SSH into my mac from another machine on out LAN I can connect no problems.
If I try and SSH into another server (not my local machine) from my remote server, I can get connected up with no problems.

So the above facts make me think that I am in the clear with regards to firewalls etc on the local and remote machines.

I'm sure I must be missing something quite obvious here, but for the life of me I can't get a handle on it.

Any help, links or general nudging in the right direction would be greatly appreciated!

Best Answer

If when you connect back to your local it allows you to login before hanging, then this isn't the answer. If you don't get that far, you're probably not getting back to your Mac (either not getting anywhere or hitting SSH on a gateway). Try a reverse tunnel (it will require GatewayPorts set to On in sshd_config on your server, but I believe this is default):
you@yourMac$ ssh -R 2000:localhost:22 user@remoteserver
That should allow you to connect to the server as normal, but also open a tunnel so that you can connect back on port 2000 (any port over 1024 should work), so you@yourserver$ ssh -p2000 user@localhost

EDIT: Changed hostname to localhost