FreeBSD as a cloud VM SSH jump host
Here are my notes on using FreeBSD ARM64 on Azure to remotely access my home network using SSH.
Uses for a cloud VM SSH jump host
There are several reasons I want to remotely access my home (IPv6-only) lab network, either from a laptop tethered to my phone, Termux on my Android phone, or from a work device.
-
Home automation
- For home automation I use Home Assistant (HA). I either want to display the HA web interface locally, or just check on HA logs, etc.
-
Checking on home lab servers
- Sometimes I have to remotely debug a service running on one of my home lab servers.
-
Remote desktop
- RDP gets me into my Windows machine to check on mail etc.
-
Boredom
- Sometimes I'm sitting in an airport or whatever and I just need a way to pass the time, and there's always something on my to-do list for my home lab.
Home lab sshd for remote access
I don't want to open any ports on my home OpenBSD router. I also prefer to not allow SSH logins directly into my router from a remote client. Instead I want a machine that's always up and running a dedicated sshd FreeBSD jail.
On that FreeBSD jail, only SSH key authentication is allowed. There are other sshd_config settings that further lock things down. Look for some good resources online on how to make your sshd the most secure for environment.
ssh -J option
The ssh client has an option to connect to the destination host by "jumping" through another host. What's cool about this is how trust works between the the 3 hosts. Given hostA as the client, hostB the jump host, and hostC the destination (sshd jail), the connection path looks like this:
hostA --> hostB --> hostC
The trust relationship works like this:
- hostB trusts hostA.
- hostC trusts hostA.
- hostC does not trust hostB.
Assume no password auth and only key auth. Both hostB and hostC would have the client hostA's public key in their authorized_keys, but hostC does not have hostB's.
If hostB is a public endpoint on a VM and it gets compromised, you can worry less about an adversary moving easily to hostC, your home lab sshd.
Here's what the client's CLI would look like:
ssh -J user@hostB:2222 user@hostC -p 2223
This connects an SSH client to port 2222 on hostB, then connects to hostC through local port 2223 on hostB. More on port 2223 next.
SSH reverse tunnels
In the example above, port 2223 is open (only localhost, not external) on hostB to connect to hostC. This is set up with a reverse SSH tunnel. On the sshd jail on hostC a shell script can maintain an SSH connection to hostB and open the port. The script for the reverse tunnel can look something like this:
while [ true ]
do
ssh -NT -R 2223:localhost:22 \
-o ExitOnForwardFailure=yes \
-o TCPKeepAlive=yes \
-o ConnectTimeout=5 \
-o ServerAliveInterval=2 \
-o ServerAliveCountMax=2 \
-p 2222 user@hostB
sleep 5
done
Note the -R option. The script connects to hostB:2222 and opens localhost:2223.
FreeBSD VM sshd jail
I already have a FreeBSD (small, low cost) VM instance running for a simple website I use for my home weather station data and weather cam. A jail isolates the nginx server. It is easy for me to add another jail that serves as the sshd jump host.
Again, the sshd on the VM sshd jail only allows key auth and has the most secure settings focused on serving as a jump host.
The FreeBSD VM has both a public IPv4 and IPv6 address. When I tether my laptop, my phone gives an IPv6 address. If no IPv6 is available, I can still get through to my IPv6-only home lab network via IPv4.
Summary
Cool, I now have a way to securely access my home lab network without having to open a port on my home router. Using SSH opens a lot of ways to access various services on my home lab network remotely. For example, to access my HA instance directly from my remote laptop browser, I can set up an SSH tunnel (-L option). It looks something like this:
ssh -J user@$hostB:2222,user@localhost:2223 user@ha-server -NT -L 8123:localhost:8123
The connect path looks like this:
hostA --> hostB:2222 --> hostB:localhost:2223 --> hostC --> ha-server
This opens port localhost:8123 on hostA (laptop) by jumping to hostC which then connects to ha-server to set up the SSH tunnel for HA's port 8123. From my laptop, I use my browser to connect to http://localhost:8123 to log into my HA dashboard. I'm not concerned about using http instead of https because I know the identity of each of the sshd instances, and SSH provides encryption.
I find SSH and FreeBSD jails both great tools to remotely access my home network.