SSH connection outside the local network

Translations available: | "Spanish" |

This post arose from a university job (for a Raspberry); however, it served me with other similar needs, to connect remotely without opening ports on the router.

To achieve an SSH connection (or another protocol) outside the local area, in a simple way, it seems this, for different reasons (it could be by enabling ports on the router, only that this according to the operator can become very difficult to achieve due to your policies among other things), then let's continue, you need to install Ngrok capture of ngrok official site

In the case of a Raspberry you need the version Linux(ARM) or in console:

1wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip

Then the unzip is done as explained in the ngrok console tutorial:

1unzip ngrok-stable-linux-arm.zip

The next thing is to register and/or enter ngrok, and once there, go to this link where it will show the token for your account

Once knowing your token you have to execute on your device:

1./ngrok authtoken XXXXXHereYourTokenXXXXXXX

With that it should be configured, all that remains is to listen to port 22, which is used by SSH, as follows:

1./ngrok tcp 22

it is then when it shows them the Host and port it will point PoC ngrok

This shows at Forwarding the TCP address and port that enables us to work with our Raspberry.

In this case, it was 0.tcp.ngrok.io and port 17271, that is, instead of our local IP and default port (22), these must be specified to access our device outside the local area, that is:

1ssh pi@0.tcp.ngrok.io -p17271

and that would be :D On the ngrok page you can review the variety and protocols available, with the same logic.

-Hackers are People Too 😜