WireGuard — VPN on keys
A fast VPN on a key pair instead of passwords; the private key in wg0.conf needs permissions, like an SSH key.
Cheat sheet
5 commands Printable version-
wg genkey | tee priv | wg pubkey > pubgenerate keys -
sudo wg-quick up wg0bring the tunnel up -
sudo wg-quick down wg0bring the tunnel down -
sudo wg showpeers, handshake, traffic -
sudo systemctl enable wg-quick@wg0autostart - conf: [Interface] Address/PrivateKey/ListenPort ; [Peer] PublicKey/AllowedIPs/Endpoint
Overview
WireGuard is a simple, fast VPN built on keys (like SSH:
a private/public pair). It creates a wg0 interface with an encrypted
tunnel between peers. Managed with wg/wg-quick.
Options
Troubleshooting
4The tunnel is up, but there's no connectivity
sudo wg show — is there a "latest handshake"? No handshake means the
keys don't match, the Endpoint is wrong, or port 51820/udp is closed by
the firewall on the server.
There's a handshake, but pings don't go through
AllowedIPs doesn't include the needed addresses (for each peer, it's
"which IPs are behind it"). For routing outward, add ip_forward plus
NAT.
Can't connect after a reboot
systemctl enable wg-quick@wg0. Check wg-quick up manually for errors.
Asymmetric / one side sees the other, but not vice versa
AllowedIPs must be configured consistently on both sides. One
side's public key must be in the other's [Peer] section.
Danger zone
wg0.conf contains the private key in plain text — the file must be
readable only by root (chmod 600, owned by root, which is also the
default wg genkey produces when redirected into a file). A leaked
private key is equivalent to a leaked password: with it, someone can
stand up their own node with the same public key inside the network.
Don't commit a wg0.conf with real keys to git, and don't send it in a
shared chat — sharing the public key with a new peer only needs wg
pubkey.
See also
Found an inaccuracy? Report an error in the article