SSH Connection – Initiate from Server to Client

sshssh-tunneling

We can easily connect via ssh to the remote machine that has public IP.

But now I have a remote machine without public IP, and I need to connect to it from my machine that does have public IP. So that, remote machine should initiate this connection (add a client).

I need it because there is my grandfather on computer without public IP, and he needs help with his system sometimes.

In similar situation on Windows I've used VNC connection (by TightVNC), TightVNC server has an option "Add a client": user just entered client's IP (i.e. my public IP), my client is already in "listening mode", and when "server" adds a client, connection is initialized.

So, is it possible to perform the same trick with SSH connection?

Best Answer

By definition, the client is the one that initiates the connection.

For your problem, I think a simple solution would be building a reverse tunnel.

On the computer without public IP:

ssh -R 2222:localhost:22 loginOfServerWithPublicIP@publicIP

This connects to the server by SSH and builds a tunnel from the server with public IP on port 2222 to the computer without public IP on port 22 (SSH).

And then on the server:

ssh -p 2222 loginOfComputerWithoutPublicIP@locahost

The connection is redirected from the port 2222 of the server to the port 22 of the computer by the first tunnel. You may want to use tool like autossh to make the tunnel more resilient (i.e. restart it automatically when it shuts down).

Related Question