A small VPN replacement with SSH

Summary

On Hackaday, Al Williams shows how to build a simple VPN between two computers with existing SSH access. SSH creates a tun device on both sides and routes traffic over the encrypted connection; the NetworkManager plugin for SSH turns this into an ordinary connection. It requires root on both sides and suitable settings in the SSH server.

Preparing server and client

On the server, PermitTunnel must be set to yes in /etc/ssh/sshd_config, possibly also AllowTCPForwarding. Because both sides create a tun device, root is needed on both ends; Williams briefly allows root login, installs a key with ssh-copy-id and then switches to PermitRootLogin prohibit-password.

Manually, a call such as ssh -w 100:100 with the option Tunnel=point-to-point is enough; it creates tun100 on both sides and assigns point-to-point addresses. The network-manager-ssh package is more convenient and handles the tunnel as a VPN connection in NetworkManager.

What it is good for

Williams names two purposes: reaching your own network while travelling, for example the network printer, and hiding your location from websites. For the first case he recommends a dedicated router or a Raspberry Pi as the VPN endpoint in the long run.

Ideas

  • An existing SSH server is enough for a simple VPN.
  • ssh -w creates tun devices on both sides.
  • PermitTunnel must be explicitly allowed on the server.
  • Root login by key without a password keeps access lean.
  • The NetworkManager plugin turns the tunnel into an ordinary VPN connection.
  • Snippets in /etc/ssh/ssh_config.d survive system updates.

Insights

  • Combining existing, proven services is often faster than setting up new ones.
  • Convenience in key checking costs exactly the protection the tunnel is supposed to provide.

Facts

  • In OpenSSH, PermitTunnel defaults to no.
  • For tun devices, SSH needs root privileges on both sides.
  • PermitRootLogin prohibit-password allows root only with a key.
  • Debian Trixie includes network-manager-ssh 1.2.11.

References

Critique

  • Williams suggests disabling StrictHostKeyChecking; this removes the check of the server key and a man in the middle goes unnoticed. Confirming the key once by hand is the right way.

Remarks

  • The example command uses ifconfig, which current distributions have mostly replaced with ip.

Recommendations

  • Confirm the server key once as root instead of disabling the check.
  • Allow PermitTunnel only for the key that actually needs the tunnel.
  • Use WireGuard for permanent connections, because TCP tunnels retransmit twice on packet loss.

Read the original article

Search the Web Archive

Found a mistake or have something to add? Get in touch.