Setup REveres ssh
- Make sure SSH is installed on both machines
sudo apt-get update
sudo apt-get install openssh-server
- 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).
-f
and-N
: Tells SSH to go into the background and not execute any remote commands, respectively.-R
: Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.
- 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
- SSH into your remote machine
ssh froderick@example.com
- Onec inside, you can reverse ssh to the hidden machine with
ssh -p 2222 localuser@localhost