๐Ÿฅ’ Wanna access your home server remotely?

Sometimes you don't have physical access to your machine.

Step 1 (do this while still having physical access)

Get a cheap VPS, or use the cloud, you're basically are going to want to own static IP. How come you don't have this yet? If you're a student / cheap / cloud-crazy / whatever-the-opposite-off-cloud-crazy-is.

I'll assume the WAN IP address that you own is 198.51.100.0 and that you're able to login to a Linux server that has this IP address setup using
ssh root@198.51.100.0.

So what you'll want to do from the device you want to remotely access is:

# run this on the device you want to be able to access later on, remotely
ssh -f -N -T -R22222:localhost:22 root@198.51.100.0
# it will be running in the background, you can check using:
# ps aux | grep "ssh -f"

Assuming you have ssh running on port 22, and port 22222 is available.

Step 2 (hopefully you've tested this using 3G)

Photo by Ross Parmly / Unsplash

So here we go, you need to get ssh access.

ssh -t root@198.51.100.0 "ssh -p 22222 user@localhost"

done.

Bonus

Remember that setting your router had that would allow you to access the router remotely? So set it to 198.51.100.0.

ssh -D 8181 root@198.51.100.0

will set up a socks5 proxy on localhost:8181, allowing you to access the web UI using the WAN IP address for your router.

Bonus 2

# to get wan address
curl https://api.ipify.org

Moar?

TODO

Setup autossh in case the tunnel disconnects.

IaC

Backups, always backups.