ubuntusshtunneling

Accessing SSH tunnel from third machine


I have set the following ssh tunneling, to access office machine from home:

[execute from office machine] Setup connection Office -> Home (as Home has public IP). Setup reverse tunnel from office machine to home:

ssh -CNR 19999:localhost:22 homeuser@home

[execute from home machine] Connecting to office from home. Using tunnel from the step 1:

ssh -p 19999 officeuser@home

Now, how can I access my office machine from a third machine, and not the home one ? I can access my home machine from any machine on the internet.

Thanks


Solution

  • From the SSH documentation for the -R parameter:

    By default, TCP listening sockets on the server will be bound to the loopback interface only. This may be overridden by specify‐ ing a bind_address. An empty bind_address, or the address ‘*’, indicates that the remote socket should listen on all interfaces. Specifying a remote bind_address will only succeed if the server's GatewayPorts option is enabled (see sshd_config(5)).

    So you have to use:

    ssh -CNR 0.0.0.0:19999:localhost:22 homeuser@home
    

    If you use OpenSSH sshd server on your home server you need to set the GatewayPorts option in /etc/ssh/sshd_config to yes.