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.

I want to connect to my computer(local) behind NAT through a public accessible server(public).

On local:

ssh -g -R 8000:localhost:22 user@public

Then on public:

ssh -p 8000 user@public 

But I am getting error: Connection refused.

When I login to the public server, I can verify that the tunnel is working by:

ssh -p 8000 localhost

Which opens ssh on the local computer.

Am I suspecting something wrong that the public server should act as transparent proxy? Or how to make it work like that.

share|improve this question

2 Answers 2

up vote 9 down vote accepted

SSH remote port forwards will default binding to localhost/loopback for security purposes. It's not often preferable to allow other hosts access to your forwarded ports.

To override this behaviour you will need to do two things:

  • Enable the GatewayPorts option on the server.
  • Specify a bind address, or * to bind to all addresses, on the client.

    ssh -R \*:8000:localhost:22 user@public
    

Escape the asterisk to ensure that your shell doesn't expand it.

share|improve this answer

This looks more like a problem with the settings on the remote computer public. By default the openssh sshd (which I guess is the one being used) the setting GatewayPorts turned to no, which forces remote port forwarding to only listen on localhost.

The solution would then be to edit your /etc/ssh/sshd_config (or equivalent), setting GatewayPorts to yes or to clientspecified. In case you choose the later you will have to change your tunnel request to something like -R *:8000:localhost:22 instead.

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.