Reverse SSH Tunnel

Installation

sudo apt install autossh

set up logging:

echo 'export AUTOSSH_LOGFILE="$HOME/autossh.log"' >> ~/.bashrc

Usage

autossh -M 20000 -fNn your_public_server -R 1234:localhost:22 -C
  • -M: the monitor port
  • -f: run in background
  • -N: no execution, just for forwarding
  • -n: redirect stdin to /dev/null
  • -T: disable pseudo terminal emulation
  • -R:
  • -C: compress all data
autossh -f -nNT -i ~/keypair.pem -R 2000:localhost:22

Start at Reboot with cron

You probably can't set this up with a key that has a passphrase on it.
crontab -e

enter the following

@reboot sleep 300 && autossh -M 20000 -f -Nnt -R 2201:localhost:22 <servername> -C

External References