Have you ever wanted to ssh to your Linux box that sits behind NAT? Now you can with reverse SSH tunneling. This document will show you step by step how to set up reverse SSH tunneling. The reverse SSH tunneling should work fine with Unix like systems.

Let’s assume that Destination’s IP is (Linux box that you want to access).

You want to access from Linux client with IP

Destination (

1. SSH from the destination to the source (with public ip) using command below:

ssh -R 19999:localhost:22 sourceuser@

* port 19999 can be any unused port.

2. Now you can SSH from source to destination through SSH tuneling:

ssh localhost -p 19999

3. 3rd party servers can also access through Destination (

Destination (

3.1 From Bob’s server:

ssh sourceuser@

3.2 After the sucessful login to Source:

ssh localhost -p 19999

* the connection between destination and source must be alive at all time.

Tip: you may run a command (e.g. watch, top) on Destination to keep the connection active.

This is the script to add in the cronjob best all 5 min:

if [ -z "`ps | grep use[r]`" ]
ssh -R 18000:localhost:22 -f -N -T user@zurich.host.com -p 6022 &
echo "start autotunnel" >> tunnellog.log
echo "autotunnel is started" >> tunnellog.log

to add the ssh key:

ssh user@ -p 6022 mkdir -p .ssh

cat .ssh/id_rsa.pub | ssh user@ -p 6022 ‘cat >> .ssh/authorized_keys’

don’t forget on the target:

ssh-keygen -t rsa