Reverse SSH Tunneling Between Two Linux Hosts

< 1 min read

Reverse SSH tunneling allows you to access a host by traversing a firewall / nat router by creating an outbound session from the obfuscated machine.   SSH is a very useful and powerful tool when comes time to access a remote machine or server securely. If you have a machine behind a firewall or NAT router – we can use this method to create a tunnel to a remote server;  from which you can ssh to a port on the remote server to access a local shell session on the server behind the network obstruction.

Install AutoSSH with the following:

 sudo apt install autossh 

AutoSSH can be run from systemd, rc.local, chron or any other method you prefer.

autossh -M 10900 -fN -o "PubkeyAuthentication=yes" -o "StrictHostKeyChecking=false" -o "PasswordAuthentication=no" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R remote.host.com:16001:localhost:22 root@remote.host.com

In the above 16001 is used as the port on the remote server which you will connect to, this can be changed to your liking.  After autossh is running, you can connect to your tunnel (from the target server, so connect via ssh from the client):

 ssh -p 16001 root@localhost 

Note that with this example, passwordless ssh is already configured.  Test your connection prior to setting up autossh!


We want to hear your thoughts about this. Is there anything in particular that you love about it? What can we do to improve our services and experience? Leave a comment below or open a ticket on our helpdesk and we’ll personally review all suggestions and feedback. 

About Servercheap.NET

Since it was founded in 2015, Servercheap has always strived to provide its clients with enterprise-level performance at an unbeatable cost. Servercheap offers a wide range of customizable hybrid and virtual private server hosting services. All Servercheap clients enjoy a 99.9% uptime SLA and 24/7 rapid response support team.
At Servercheap, our core directive has always been to provide our clients with the best services and infrastructure possible, whether you’re hosting a game server, a high-intensity database, a development environment, or anything in-between.
For more information, visit https://www.servercheap.net

Leave a Reply

Your email address will not be published. Required fields are marked *