Reverse SSH

By Greg Gallardo

Setup Reverse ssh

  1. Make sure SSH is installed on both machines
sudo apt-get update
sudo apt-get install openssh-server
  1. On your hidden machine run
ssh -f -N -R 2222:localhost:22 someuser@example.com  -i ~/.ssh/id_rsa_rev

This command opens an SSH connection to greggallardo.com (the machine exposed to the internet) sets up aa tunnel back to localhost (the home machine) on port 22 (the standard SSH port).

  1. make it persist with cron
crontab -e

tell it to use

@reboot sleep 60;ssh -f -N -R 2222:localhost:22 someuser@example.com  -i /home/locakuser/.ssh/id_rsa_rev

Connect from the outer machine

  1. SSH into your remote machine
 ssh froderick@example.com
  1. Onec inside, you can reverse ssh to the hidden machine with
ssh -p 2222 localuser@localhost