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.
Prerequisites & Design
Before you begin, make sure you have the following:
- A VPS running Debian 13 (Trixie) with root or
sudoaccess - 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.
Debian 13 ships WireGuard in the kernel. The only package you need is wireguard-tools.
Install WireGuard on the Server
Install the tools. There is no daemon to configure: wg-quick brings the interface up from a config file.
sudo apt update && sudo apt install -y wireguard-tools
Check that the kernel module is available:
sudo modprobe wireguard && lsmod | grep wireguard
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.
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:
umask 077
wg genkey | tee client.key | wg pubkey > client.pub
wg genpsk > psk.key
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.
Configure and Start the Server
Create the interface config. Replace the placeholders with the contents of the corresponding files.
[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:
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.
ufw allow 51820/udp
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.
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.
[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):
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
sudo apt install -y wireguard-tools
sudo install -m 600 wg0.conf /etc/wireguard/wg0.conf
sudo wg-quick up wg0
Verification
From the client, check the handshake and reach the server through the tunnel:
sudo wg show
ping -c 3 10.8.0.1
ssh [email protected]
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.
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.
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.
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.
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:
wg syncconf wg0 <(wg-quick strip wg0)
If the handshake never happens, check in this order:
- Port: is
51820/udpopen in the provider firewall and on the host? Verify the server is listening withss -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
Addressmust match the server peer'sAllowedIPs. - Logs:
journalctl -u wg-quick@wg0shows config parse errors on the server.
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.