Skip to content

Instantly share code, notes, and snippets.

@rrmhearts
Created March 25, 2020 13:52
Show Gist options
  • Save rrmhearts/9f3f8427e7b2c9dd222afe8d3c5ff189 to your computer and use it in GitHub Desktop.
Save rrmhearts/9f3f8427e7b2c9dd222afe8d3c5ff189 to your computer and use it in GitHub Desktop.
ssh 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment