WireGuard from scratch on a Linux VPS
Install WireGuard, generate keys, write interface configs, and bring up a single peer tunnel on a Linux VPS.
Published here , updated · 5 sources · Resume reading
WireGuard builds encrypted tunnels with public keys and a short config surface [1]. This walkthrough stands up one VPS peer and one client peer from the official quick start shape [1]. Glossary first if needed: what is a VPN. Product tradeoffs: WireGuard vs Tailscale vs OpenVPN.
Quick start (under a minute)
On any Linux machine with wireguard-tools installed per the install page [2]:
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
wc -c privatekey publickeyYou should see two small key files (roughly 45 bytes each with newline) and nonzero byte counts. Never paste the private key into chat or email [1].
WireGuard tools were not available on this draft host, so the byte counts below are not measured here. Run the block on your VPS and client after install [2].
Draw one server peer and one client peer
Each side lists the other's public key under [Peer]. Inner tunnel addresses live on [Interface] [1].
Install tools, then generate keys
Install WireGuard for your distribution from the installation page [2]. Repeat key generation on the VPS and on the client:
umask 077
wg genkey | tee privatekey | wg pubkey > publickeyYou should have privatekey readable only by your user and publickey safe to copy into peer blocks [1]. Exchange public keys out of band you trust.
Write matching interface configs
Minimal VPS wg0.conf aligned with the quick start [1]:
[Interface]
PrivateKey = <vps-private>
Address = 10.0.0.1/24
ListenPort = 51820
[Peer]
PublicKey = <client-public>
AllowedIPs = 10.0.0.2/32Client mirror [1]:
[Interface]
PrivateKey = <client-private>
Address = 10.0.0.2/24
[Peer]
PublicKey = <vps-public>
Endpoint = <vps-public-ip>:51820
AllowedIPs = 10.0.0.0/24
PersistentKeepalive = 25AllowedIPs decides which destination IPs ride the tunnel toward that peer [1]. Start with tunnel-only prefixes before you route all traffic with 0.0.0.0/0. PersistentKeepalive = 25 matches the quick start guidance for clients behind NAT [1].
Restrict file permissions on configs that hold private keys. wg-quick expects root for up/down on most systems.
Bring the interface up and verify
sudo wg-quick up wg0
sudo wg show
ping -c 3 10.0.0.1Per the quick start, wg show should list the interface, listening port, peer public key, and a recent handshake after traffic flows [1]. Example shape (values will differ on your machine):
interface: wg0
public key: <vps-public>
private key: (hidden)
listening port: 51820
peer: <client-public>
allowed ips: 10.0.0.2/32
latest handshake: 1 minute agoOpen UDP 51820 (or your chosen port) in the VPS provider firewall and any host firewall. If clients must use the VPS as an internet exit, enable IPv4 forwarding and SNAT on the VPS. Those distro-specific steps are outside this quick start; keep them in version control when you add them.
Tear down safely:
sudo wg-quick down wg0Rotate keys without renaming the universe
WireGuard identifies peers by public keys, not by DNS names inside the tunnel [1]. When you rotate a laptop key, update only the [Peer] public key on the VPS and the matching private key on the client. Inner IPs (10.0.0.2/32) can stay put if the same machine keeps that role.
Document which key belongs to which device in your password manager or inventory. The config file is short precisely because it does not carry X.509 subject lore.
Split tunnel versus full tunnel on AllowedIPs
AllowedIPs on the client decides which destination prefixes enter the tunnel [1]. A split setup lists only RFC1918 lab nets or a single /32 for one service. A full-tunnel setup lists 0.0.0.0/0 and ::/0 so general internet egress exits through the VPS. That second pattern turns the VPS into a router with legal and abuse implications at your provider. Choose deliberately and log the choice in your runbook.
Server-side AllowedIPs on the VPS peer entry is usually the client's tunnel address (/32) so the server knows which ciphertext belongs to which inner IP.
Firewall checklist before you blame WireGuard
When wg show never records a handshake, walk this ordered list:
| Check | What to verify |
|---|---|
| UDP port | Provider security group allows your ListenPort |
| Correct endpoint | Client Endpoint IP matches current VPS public IP |
| Keys swapped | Each side pasted the other's public key, not its own |
| Time sync | Large clock skew is rare but NTP helps logs make sense |
| Local firewall | ufw or nftables on VPS allows UDP in |
ICMP ping across tunnel inner IPs is a sanity check after handshake appears [1]. It does not prove UDP crypto is configured for every app you care about.
When you want mesh instead of hand-written peers
Hand-written [Peer] blocks scale poorly when every laptop talks to every server. Mesh products add identity, NAT traversal, and ACLs. Tailscale is one path documented on this site: Tailscale for agent machines. Stay on raw WireGuard when you want full control of keys, routes, and audit on a single VPS.
Log enough to audit later
Keep a dated note of which public key belongs to which device, the VPS public IP, and whether you enabled full-tunnel routing [1]. When an employee laptop disappears, you remove its peer block and reload the interface. WireGuard does not ship a central audit UI; your version control and firewall logs fill that gap.
Store private keys only on the devices that need them. Backup configs without private keys if you must archive structure, but rotate after incidents.
Mobile clients import the same [Interface] / [Peer] text through OS-specific WireGuard apps; the cryptography matches Linux [1]. The quick start remains the reference for key generation even when the UI wraps wg-quick differently.
IPv6 inner addresses work the same way with /64 or /128 assignments when your provider routes them. Dual-stack clients list both 0.0.0.0/0 and ::/0 in AllowedIPs only when you intend full-tunnel egress for both families [1].
Failure modes worth naming
Treating WireGuard like OpenVPN file soup. WireGuard configs are short and key-centric [1].
Pasting private keys into tickets or screenshots. Rotate if leaked.
Forgetting UDP in the cloud firewall while TCP SSH still works. The tunnel never establishes.
Setting AllowedIPs = 0.0.0.0/0 on the client before you understand split tunneling. You can send all traffic through the VPS on purpose, but that is a routing decision [1].
Skipping PersistentKeepalive on NATed clients and blaming WireGuard for idle disconnects [1].
Encryption replaces application auth. WireGuard gives you a private channel, not user login.
Bring wg0 up on the VPS and client, then ping across the tunnel before you open SSH to the world. If the word VPN still feels fuzzy, what is a VPN names the threat model this tunnel fits into. When you wonder whether hand-edited peers are worth the hassle, WireGuard vs Tailscale vs OpenVPN lays out the product trade space without pretending one logo fits every team.
Send this to the friend about to expose SSH to the world instead of a tunnel.

Keep this guide
Filed under Dev tools, Dev explainers
Questions about this guide
What is WireGuard?
WireGuard is a VPN protocol built around Curve25519 keys and a small kernel implementation. This page follows the official quick start for a point-to-point tunnel.
Do I need a commercial VPN brand?
No. You can terminate WireGuard on your own VPS and connect a laptop as a peer. Consumer VPN apps are a different packaging of similar ideas.
Which ports must be open?
UDP on the ListenPort you configure, often 51820. You also need IP forwarding and NAT on the VPS if clients should reach the broader internet through the tunnel.
Where does Tailscale fit?
Tailscale uses WireGuard under the hood and adds identity and coordination. See the Tailscale for agent machines post when you want mesh without hand-written peers.
What is AllowedIPs?
AllowedIPs is the cryptokey routing table: which destination prefixes should be encrypted toward this peer. It is not merely a firewall convenience.
Sources
- WireGuard: Quick Start, accessed 2026-12-03wireguard.com
- WireGuard: Installation, accessed 2026-12-03wireguard.com
- Full Byte Developer: What is a VPNfullbytedeveloper.com
- Full Byte Developer: WireGuard vs Tailscale vs OpenVPNfullbytedeveloper.com
- Full Byte Developer: Tailscale for agent machinesfullbytedeveloper.com