SSH to Remote Devices Running Linux from Anywhere
How to setup a gateway and utilize a few tools to securely connect to your target devices through reverse SSH Tunneling.
2/11/20181 min read
Introduction
Remote devices like IoT devices are everywhere nowadays and probably you are here because you have been dealing with them somehow. If you need to SSH to your devices which are on an external network such as cellular network with dynamic or local IP addresses, this is a right place to learn how to setup a gateway and utilize a few tools to securely connect to your target devices through reverse SSH Tunneling.
Prerequisites
A Linux(1) machine (gateway) with a public static IP address (e.g. x1.x2.x3.x4) that can be SSHed in. This can be a tiny cloud server or your local computer.
A Linux(1) device with private (or any type) IP address that can be SSHed in.
SSH is installed and started on both machines above.
A user with sudo privileges on both machines above
(1) Ubuntu 18.04 LTS is used in this post. You may use newer versions or other distributions.
How It Works
The remote devices automatically SSH to the gateway machine to establish a reverse SSH tunnel using pre-assigned ports which are then used to SSH to the devices back from the gateway or any machine connected to the internet.
NOTE: REPLACE THE X1.X2.X3.X4 WITH A REAL STATIC IP ADDRESS.


Part 1. Gateway Server
This server is used to access the devices when they are connected to the internet. Basically, the devices establish a persistent reverse SSH tunnel to this server once connected to the internet and let the users securely connect to them using SSH via this server.
Setup Instructions
CREATE A PASSWORD-LESS USER ACCOUNT
The password-less user “autotunnel” is used by the remote devices later to SSH to the gateway server to establish a reverse SSH tunnel.
Add a user called “autotunnel” and unlock it: