10 hours of jetlag and rainy afternoon naps don’t mix. It’s 2 minutes to 2AM here in Provo, UT and I can’t sleep so I’m blogging.
I want to ssh into a machine that doesn’t have any external IP. In the case of my situation at home, I get a 192.168… IP from my ISP because of a shared connection. In other cases, I have VM’s with natted IP’s that also have no direct way in.
I could pay for a VPN service and vpn into these machines, but instead I’m using a free way of doing it. I use Tor.
Here’s how it works, the Tor service reaches out to the Tor network and is listening on port 22 (or whatever port I choose for ssh) for incoming requests. I use “torsocks ssh zzzzzzzzz.onion” from my laptop and I am in. This bypasses the external internet and gives me a pretty secure route from my laptop to my home machine only via Tor.
Here’s how I set it up with OpenSUSE
On your remote or inaccessible server:
$ sudo zypper in tor
This installs the tor service and the torsocks proxy app.
$ sudo vim /etc/tor/torrc
Uncomment the following lines:
HiddenServiceDir /var/lib/tor/hidden_service/ HiddenServicePort 22 127.0.0.1:22
$sudo systemctl start tor
The service is now started and you should have a new .onion address
$ cat /var/lib/tor/hidden_service/hostname
On your local machine/laptop/etc:
$ sudo zypper in tor
$ sudo systemctl start tor
$ torsocks ssh xxxxxxxxx.onion
This is a cool trick. Of course you can use it on any server/VM/etc even if they do have accessible IP’s. In those cases, I suggest that you close the firewall on port 22 and allow it to be only accessible via Tor. There is no need to have extra ports open to the internet.
Using Tor is a great way to add security to your network communication. In addition to the SSH encryption, the packets have additional encryption due to the nature of how Tor works.
Anyway, I hope this helps people out if you’re like me and have to make do with an ISP that makes using the web just a little harder.
One last thing. Tor is more laggy than a straight connection. You’re not doing anything wrong, it’s just a side-effect of how this all works.