Install WireGuard VPN on a VPS in 10 minutes

From ssh root@ to a working tunnel with one connected client. Bare-metal WireGuard on Ubuntu — no Docker, no web UI, no abstraction. Once you understand this, the wrapper tools (wg-easy, WG Dashboard) make sense.

Disclosure: contains an affiliate link to Inferno VPS.

What you'll end up with

Prerequisites

Tested on Ubuntu 22.04 LTS, WireGuard 1.0.20210914, on a $3.49 Inferno VPS in Stockholm — ample bandwidth for a personal VPN.

Step 1 — Install WireGuard

sudo apt update
sudo apt install -y wireguard wireguard-tools qrencode

qrencode isn't strictly required, but it lets you import the client config on a phone by scanning a QR code, which is the easiest path.

Step 2 — Generate server keys

cd /etc/wireguard
sudo umask 077
sudo wg genkey | sudo tee server_private.key | sudo wg pubkey | sudo tee server_public.key
sudo cat server_private.key
sudo cat server_public.key

Copy both values into a scratch file on your local machine — we'll paste them into the server and client configs. umask 077 ensures the key files are 600 (root-only).

Step 3 — Server config

sudo nano /etc/wireguard/wg0.conf
[Interface]
PrivateKey = <paste server_private.key>
Address = 10.7.0.1/24
ListenPort = 51820
SaveConfig = false

# NAT for outbound traffic — replace eth0 if your public interface is named differently
PostUp   = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

# Peers (clients) — we'll add the first one in Step 6

Find your public interface name with ip route get 1.1.1.1 | awk '{print $5}' — usually eth0 on bare-metal Ubuntu, sometimes ens3 or enp1s0 on virtualized hosts. Replace if needed.

Step 4 — Enable IP forwarding

sudo nano /etc/sysctl.conf

Uncomment or add:

net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1

Apply without reboot:

sudo sysctl -p

Step 5 — Firewall

sudo ufw allow OpenSSH
sudo ufw allow 51820/udp
sudo ufw enable
sudo ufw status numbered

If you're connected over SSH from a residential IP without a static address, double-check you can SSH back in from a second terminal before enable-ing UFW. Lockouts are common.

Step 6 — Start the tunnel

sudo systemctl enable --now wg-quick@wg0
sudo systemctl status wg-quick@wg0
sudo wg show

wg show output should list interface wg0, the public key, the listen port, and an empty peer list. No errors. If it reports "Address already in use," another VPN or interface is holding the same address — pick a different range (e.g. 10.8.0.1/24).

Step 7 — Generate the first client

On the server, generate the client's keys:

cd /etc/wireguard
sudo wg genkey | sudo tee client1_private.key | sudo wg pubkey | sudo tee client1_public.key

Create the client config (this will be transferred to the phone/laptop):

sudo nano client1.conf
[Interface]
PrivateKey = <paste client1_private.key>
Address = 10.7.0.2/24
DNS = 1.1.1.1, 9.9.9.9

[Peer]
PublicKey = <paste server_public.key>
Endpoint = YOUR.VPS.PUBLIC.IP:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

AllowedIPs = 0.0.0.0/0, ::/0 routes all client traffic through the tunnel — a full VPN. For split tunneling (only specific traffic) see the dedicated guide.

Step 8 — Register the client on the server

Append the peer block to /etc/wireguard/wg0.conf:

[Peer]
# client1
PublicKey = <paste client1_public.key>
AllowedIPs = 10.7.0.2/32

Reload WireGuard (no service restart needed):

sudo systemctl restart wg-quick@wg0
sudo wg show

The peer should now appear in the list, with "latest handshake" empty (no connection yet).

Step 9 — Connect from a client

Phone (iOS / Android)

Install the WireGuard app from the App Store / Play Store. On the server:

sudo qrencode -t ansiutf8 < /etc/wireguard/client1.conf

Scan the QR code with the app. Toggle the tunnel on. Visit ifconfig.me — it should show your VPS IP, not your phone carrier's IP.

Laptop (any OS)

Copy the file off the server:

scp deploy@your-vps-ip:/etc/wireguard/client1.conf ~/Downloads/

Import it into the WireGuard desktop app (Windows / macOS / Linux). Activate. Same test on ifconfig.me. See our client setup guide for screenshots.

Adding more clients

Repeat steps 7 and 8 for each new client with a unique IP (10.7.0.3/32, 10.7.0.4/32, ...). Keep a one-line note of which IP belongs to which device — at 10+ clients this becomes the single most useful piece of documentation you own.

Verifying everything works

# On the server, watch the tunnel handshakes
sudo wg show

# Latest handshake should update every minute or so once a client connects
# Transfer rx/tx should increment as the client browses

If latest handshake stays empty after the client toggles on:

  1. UFW is not allowing 51820/udp.
  2. The VPS provider's external firewall blocks UDP traffic (rare; check provider docs).
  3. The client's PublicKey in wg0.conf doesn't match the actual key on the client.
  4. The client's Endpoint points to the wrong IP/port.

Securing the keys

WireGuard private keys are the entire authentication story — there is no other secret. Treat them like SSH private keys: file mode 600, never commit to git, generate fresh ones if a device is lost.

To revoke a client, delete its [Peer] block from /etc/wireguard/wg0.conf and restart the service. No revocation list needed — WireGuard simply stops accepting that public key.

Looking for a VPS for a personal VPN?

The $3.49/mo Inferno plan has more than enough bandwidth for a single-person or family VPN. Eight locations let you pick a jurisdiction and latency that fits — Helsinki, Tallinn and Stockholm are popular for privacy-friendly defaults.

View Inferno plans →

What to do next


Author: Marek Vainionpää — SRE, Helsinki. Last tested: 2026-05-22 on Ubuntu 22.04 LTS, WireGuard 1.0.20210914, Inferno VPS Stockholm.