brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: set umask 077 before wg genkey so your WireGuard VPN key stays private

Network and access
~/tips/tip-wireguard-genkey-umask

umask 077

Create a WireGuard key pair without leaving the private key readable for other users.

The usual one-liner to make WireGuard keys writes the private key to a file. With a normal umask, that file is readable by every user on the machine.

The wg man page shows the fix, and it is worth copying exactly:

umask 077
wg genkey | tee private.key | wg pubkey > public.key

umask 077 makes new files readable only by you. wg genkey prints a random private key, tee saves it and passes it on, and wg pubkey turns it into the public key you share with the other side.

Check the result with ls -l private.key: you want -rw-------.

The umask stays active for the rest of that shell session. That is harmless, but if you create other files afterwards that need to be readable by others, open a new shell or run it in a subshell:

(umask 077 && wg genkey > private.key)

For an extra layer, wg genpsk makes a preshared key that both sides add to the peer section, which the WireGuard docs describe as a hedge for the future against quantum computers.

Remember that whoever can read the private key or the config file that holds it can impersonate this peer. On a server I’d keep both under /etc/wireguard owned by root with mode 600.

Further reading: wg(8) man page

Going deeper: Why a Tailscale device vanishes after 180 days, and how to stop it

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link