Lesson 2 of 9 · 24m
Key Management Without a PKI
How to generate, store, rotate, revoke, and inventory WireGuard keys so a simple keypair system does not quietly become uncontrolled secret sprawl.
WireGuard's key model is refreshingly simple until you operate more than a dozen hosts. Then the practical questions arrive: where are private keys stored, who can read them, how are peers revoked, and how do you prove which key belongs to which machine? Teams that skip those answers end up with immutable servers carrying permanent credentials nobody can account for.
Generate keys on the host that will use them
The private key should be born on the endpoint and never leave it:
$ umask 077
$ mkdir -p /etc/wireguard
$ wg genkey | tee /etc/wireguard/wg-private.key | wg pubkey > /etc/wireguard/wg-forums.key
$ chmod 600 /etc/wireguard/wg-private.keywg genkey writes the private key; piping it into wg pubkey derives the public key. Do not email private keys, copy them through tickets, or generate them centrally because it feels convenient. Central generation creates central exposure.
A production config usually reads it indirectly:
[Interface]
Address = 10.44.0.12/32
ListenPort = 51820
PrivateKey = 4PpR7s0xExamplePrivateKeyValueDoNotUseThisKey4=Better on systemd-managed systems: use wg-quick with the private key in a root-only file and configuration permissions locked down, or use a secrets manager to render the file at provision time.
Public keys belong in inventory
The public key is not secret, but it is security-critical inventory. Record it with the hostname, owner, environment, interface address, and enrollment date:
peers:
edge-01.chi:
public_key: z8QXf4S0sP+F3U3N0N7m2C+v1kq2Fq9mFvZpY7rYy0Y=
address: 10.44.0.12/32
owner: platform
environment: production
enrolled: 2026-11-30If you cannot answer “which machine owns this key?” in one query, you do not have a key management system; you have a pile of base64 strings.
Rotation and revocation are fleet operations
WireGuard has no certificate expiry. Rotation means generating a new keypair on the endpoint, adding the new public key to relevant peers, verifying handshakes, then removing the old peer everywhere. Revocation means removing the peer entry — there is no CRL to distribute.
# on every authorized peer host
$ wg set wg0 peer OLD_PUBLIC_KEY removeThis is why automation matters. A manual key rotation over forty nodes is not a rotation process; it is an outage generator. Configuration management should render peer entries from inventory and converge every host.
Preshared keys are a narrow tool
WireGuard supports an optional PresharedKey per peer. It adds symmetric secret material as protection against future quantum attacks against the key exchange, but it does not replace peer public keys and it adds another secret to distribute. Use it for high-sensitivity fixed links, not as a universal default you cannot inventory.
Field notes
- Never copy
/etc/wireguardwholesale to clone a machine; that copies identity. - A peer entry without an owner is an incident waiting for inventory day.
- Rotate after host compromise, employee departure with admin access, accidental key exposure, or uncertain provisioning history.
- Backups of private keys must be encrypted and access-controlled, or omitted entirely when hosts can be re-provisioned.
- Test revocation regularly. Teams often discover their “automated” removal path only after a laptop is lost.
Was this lesson helpful?