My quick and dirty setup to set up a SSH tunnel to home machines from our remote web server.
This sets up a way to access our home machine via our remote web host – just do a
ssh -p PORTNUM localhost when logged in at
Setup of keys; creating a passphrase
First, make sure that you’ve created an RSA public/private key pair:
ssh-keygen -t rsa
I had to use this since I completely forgot the old passphrase I set up in the past. Now, rather than copy over to authorized_keys to the remote server it is far nicer to use:
ssh-copy-id -i ~/.ssh/id_rsa.pub USERNAME@REMOTESERVER.NET
To stop you from being asked for the passphrase every time you want to SSH into the remote server do:
.. on the (home) machine you want to access. Follow the prompts to ‘record’ your passphrase. Now we can move onto the actual port forwarding itself.
Basic port forward
Now, on the (home) machine you did a
ssh-add to, I’ve set up the forward with:
while true; do ssh -C -R PORTNUM:localhost:SSH_PORT USERNAME@REMOTESERVER.NET; sleep 5; done
SSH_PORT is normally 22. I use
sleep 5 so there is some time to escape out of this infinite loop if I want to cleanly close the session running this bash script. Thus the script is left running on untouched unless I need to kill it off.