My home network has a stupid router, by my ISP, that has no port forwarding.
But I like to do stuff in my home network, when away.
Buying a new router is out of question, I am cheap!;)
This tutorial will show you, how to reach your home, or any other closed network from anywhere.
apt-get update
apt-get dist upgrade
First update your systems, home and VPS
Add user autossh on both of your systems:
adduser autossh
Install autossh:
apt-get install autossh
Change to user autossh:
su autossh
Create ssh key:
ssh-keygen -t rsa -b 4096
Just press enter, so no password is needed
Upload public key to VPS:
ssh-copy-id -i PublicKey autossh@VPS
Test the connection:
ssh VPS
Logout to your home server and become rootagain.
Now edit rc.local:
vi /etc/rc.local
And add the following line, before exit 0:
su -s /bin/sh autossh -c 'autossh -M 21080 -q -f -N -i /home/autossh/.ssh/id_rsa -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 18022:localhost:22 autossh@VPS' >> /var/log/rc.local.log 2>&1
You might have to change /home/autossh/.ssh/id_rsa to your home autssh id_rsa path. Also VPS to your VPS IP or servername.
This tool will setup a portforwarding via ssh tunnel to your VPS from your home server.
Now you can access from your VPS your home server with following command:
ssh user@localhost -p 18022
To avoid any wrong logins just deny login to the VPS for user autossh.
vi /etc/passwd
change the login shell to /bin/false:
autossh:x:10001:10001::/home/autossh:/bin/false
Next time I will show you, how to use this tool, to switch of your TV at home and anoy your kids!
;)
This post is part #3 of my "Post every day on schedule in March" challenge .. which I already lost