geek.sonde.uk updated:
WireGuard VPN Security

WireGuard on a VPS: Private Access

Set up a WireGuard server on a Debian 13 VPS, connect to it from your laptop, and use the tunnel to reach SSH and admin panels that are no longer exposed to the public internet.

~10 min read Debian 13 (server) · macOS / Linux (client) Difficulty: Intermediate
01

Prerequisites & Design

Before you begin, make sure you have the following:

  • A VPS running Debian 13 (Trixie) with root or sudo access
  • The public IP of the VPS (not a Cloudflare-proxied hostname: WireGuard is UDP and cannot go through the proxy)
  • A client machine running macOS or Linux
  • A second, already-open SSH session to the VPS for the lockdown step

We use a tiny private network, 10.8.0.0/24. The server is 10.8.0.1 and the first client is 10.8.0.2. This is a split tunnel: only traffic for the VPN subnet goes through WireGuard, everything else keeps using your normal connection. No IP forwarding or NAT is needed, which keeps the setup minimal.

ℹ️
Note

Debian 13 ships WireGuard in the kernel. The only package you need is wireguard-tools.

02

Install WireGuard on the Server

Install the tools. There is no daemon to configure: wg-quick brings the interface up from a config file.

bash
sudo apt update && sudo apt install -y wireguard-tools

Check that the kernel module is available:

bash
sudo modprobe wireguard && lsmod | grep wireguard
03

Generate Keys

Each side has its own key pair: the private key never leaves the machine that generated it, and only public keys are exchanged. Start with the server. The umask makes sure the files are created readable by root only.

bash server
sudo -i
umask 077
cd /etc/wireguard
wg genkey | tee server.key | wg pubkey > server.pub

Now generate the client key pair on the client machine, plus an optional pre-shared key (an extra symmetric layer on top of the handshake) that you create once and copy to both sides:

bash client
umask 077
wg genkey | tee client.key | wg pubkey > client.pub
wg genpsk > psk.key
⚠️
Keep private keys private

Never paste *.key files into tickets, chats or git repositories. Only the *.pub files and the pre-shared key (over a secure channel) are meant to travel.

04

Configure and Start the Server

Create the interface config. Replace the placeholders with the contents of the corresponding files.

config /etc/wireguard/wg0.conf
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>

# Client: my laptop
[Peer]
PublicKey = <contents of client.pub>
PresharedKey = <contents of psk.key>
AllowedIPs = 10.8.0.2/32

On the server, AllowedIPs acts as an access list: this peer may only use the address 10.8.0.2. Lock down the file, then enable and start the interface at boot:

bash
chmod 600 /etc/wireguard/wg0.conf
systemctl enable --now wg-quick@wg0

Open the UDP port

WireGuard needs 51820/udp reachable from the internet. Do this in every firewall layer you use: the provider's network firewall (if any) and the host firewall.

bash ufw
ufw allow 51820/udp
ℹ️
Using Plesk?

If the Plesk Firewall extension manages your rules, add an inbound rule for UDP 51820 there instead and do not install ufw alongside it: two tools fighting over the same ruleset is a recipe for surprises.

05

Configure the Client

The client config mirrors the server one. AllowedIPs here decides what is routed into the tunnel: only the VPN subnet, so the rest of your traffic is untouched.

config wg0.conf (client)
[Interface]
Address = 10.8.0.2/32
PrivateKey = <contents of client.key>

[Peer]
PublicKey = <contents of server.pub>
PresharedKey = <contents of psk.key>
Endpoint = YOUR_VPS_PUBLIC_IP:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25

macOS

Install the command-line tools with Homebrew and place the config in the Homebrew prefix (/opt/homebrew on Apple Silicon, /usr/local on Intel):

bash macOS
brew install wireguard-tools
sudo mkdir -p /opt/homebrew/etc/wireguard
sudo cp wg0.conf /opt/homebrew/etc/wireguard/wg0.conf
sudo chmod 600 /opt/homebrew/etc/wireguard/wg0.conf
sudo wg-quick up wg0

Prefer a GUI? The official WireGuard app from the App Store can import the same file.

Linux

bash Linux
sudo apt install -y wireguard-tools
sudo install -m 600 wg0.conf /etc/wireguard/wg0.conf
sudo wg-quick up wg0
06

Verification

From the client, check the handshake and reach the server through the tunnel:

bash
sudo wg show
ping -c 3 10.8.0.1
ssh [email protected]
✅
Success

If wg show lists a latest handshake a few seconds ago and the ping replies, the tunnel works. WireGuard is silent by design: no handshake means no traffic has flowed yet, not that it is broken.

07

Lock SSH and Admin Panels Behind the VPN

This is the point of the whole exercise: once the tunnel works, SSH (and anything else administrative, such as the Plesk panel on 8443) can stop listening to the world. Instead of changing the daemon's bind address, which breaks if sshd starts before wg0 exists, filter on the interface in the firewall.

🚨
Don't lock yourself out

Keep your current SSH session open, add the VPN rule first, and confirm you can log in over 10.8.0.1 in a new terminal before removing the public rule. Make sure the provider's web console is available as a fallback.

bash ufw
ufw allow in on wg0 to any port 22 proto tcp
# test a new SSH session over 10.8.0.1, then:
ufw delete allow 22/tcp

Repeat the pattern for any other admin port, for example ufw allow in on wg0 to any port 8443 proto tcp. In Plesk Firewall, the equivalent is restricting the source of those rules to 10.8.0.0/24.

08

Adding Clients & Troubleshooting

For each new device, generate a new key pair on it, pick the next free address (10.8.0.3, …) and append another [Peer] block to the server config. Apply it without dropping existing connections:

bash
wg syncconf wg0 <(wg-quick strip wg0)

If the handshake never happens, check in this order:

  • Port: is 51820/udp open in the provider firewall and on the host? Verify the server is listening with ss -ulpn | grep 51820.
  • Endpoint: it must be the VPS's real IP or a DNS-only (grey cloud) record, never a Cloudflare-proxied one.
  • Keys: each side must hold the other side's public key, and the pre-shared key must be identical on both.
  • Addresses: the client's Address must match the server peer's AllowedIPs.
  • Logs: journalctl -u wg-quick@wg0 shows config parse errors on the server.
ℹ️
Want to route all your traffic through the VPS?

That is a full tunnel: set the client's AllowedIPs to 0.0.0.0/0, enable net.ipv4.ip_forward=1 on the server and add a NAT masquerade rule for 10.8.0.0/24. It is not needed for the access-only setup in this tutorial.