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!

  • You can browse the remote server with ssh. Or do you try to use afs? How about portforwardings and/or sftp/scp? Aug 29, 2010 at 8:29
  • Hi there. Yes I can connect and browse the directory structure of the remote server with no problems. I'm not sure what you mean, sorry. Basically the plan is this: I want to ssh into my remote Linux server from my local Mac, browse for a file and then be able to pipe it back down the established connection (or generate a new connection based on the already established one) to the local machine where a Mac app will read/edit the data before sending it back to the server. I'm not especially fussed how I achieve this in terms of involving other protocols.
    – i0n
    Aug 29, 2010 at 9:03

4 Answers 4


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

  • 2
    You have to use user@localhost in the last command
    – b0fh
    Aug 29, 2010 at 15:13
  • 1
    This was helpful, it nearly gets me to where I want to be at! I can establish the connection with reverse tunnel as above and then ssh back into my local Mac using ssh -p 2000 i0n@localhost. So how can I achieve this without knowing ahead of time that I need this functionality? In other words with an existing and standard ssh connection. Is this possible?
    – i0n
    Aug 29, 2010 at 15:52
  • Thanks b0fh, I was on my way to bed whe I wrote that =) i0n - instinctively I want to say that you can't modify an existing connection to do this, but PuTTY can do it so there must be a way. You could always send in a new SSH connection with a tunnel when you need to pipe back, but I'm guessing this is going to be done programmatically so that might not be an option. Look up Expect - if any language can ready over SSH it will be that.
    – James L
    Aug 29, 2010 at 18:13

Is your local machine accessible from the server? Can you ping it? I'm asking that because what you are doing should work if your machine is accessible. Your server is on internet or in LAN, same subnet?

Anyways if you only need to edit a file, why don't you simply use scp to copy the file to your local machine? You can use ssh to browse for the file on the remote server and when you have its path, enter in your local machine (in another terminal):

scp user@server:/path/to/file/on/server /local/path/to/save/file

To put file back, scp again switching the paths.

Obs: you don't need the initial ssh connection to use scp - it will create a new one

This above is if you need to access it in terminal. On linux (and certainly on Mac but I don't know how to do it), you can mount an ssh remote location in Networks and use the connection as you use a local disk (this is sftp and the connection is in the form: sftp://user@server:/path/to/mount and I guess this is what you need instead of a remote terminal connection so you can edit the file directly with the Mac application.


You may also want to take a look a sshfs (you need MacFuse for this). This allows you to mount directories on the remote machine and access them just like regular folders on your machine. On top of that, you could still ssh into the machine and create/search the files you need. Transferring them would then be as easy as transferring local files.


I was having the same problem but for a different reason. I want to run a script from the server to pull files from my workstation – an automated backup of my home directory pulling from the server instead of pushing the files from my workstation.

Why? Because it makes more sense to me to have the server handle the backups than to have the workstation do it. I only need one generalized script to handle multiple workstations instead of trying to keep scripts on each workstation updated.

So how do you test this? My server is headless, so I have to ssh to it but then I can't ssh or use any of the tools that work on ssh to connect back to my workstation. The reverse tunnel fills the bill. Another option is to run the test using the at command then drop the tunnel before the job kicks in. Both are somewhat clumsy but the reverse port is both easier and more flexible. Plus I already use the local port forwarding to build VNC tunnels to other computers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .