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: wg genpsk adds a preshared key to a WireGuard peer

Network and access
~/tips/tip-wireguard-genpsk-preshared-key

wg genpsk > peer1.psk

Generates a random preshared key that adds a symmetric layer on top of a WireGuard peer's key pair.

WireGuard keeps its setup small, but it does have one optional extra that many configs skip: a preshared key per peer. Making one takes a single command.

umask 077
wg genpsk > peer1.psk

The man page says wg genpsk generates a random preshared key in base64 and prints it to standard output. In the config file it goes into the [Peer] section as PresharedKey. The man page calls it optional and describes it as an extra layer of symmetric-key cryptography on top of the public-key cryptography, meant for post-quantum resistance. A symmetric key is a secret both sides share, so the peer on the other end needs the same value in its own config.

You can also add it to a running interface:

wg set wg0 peer PEER_PUBLIC_KEY preshared-key ./peer1.psk

The key has to come from a file. The man page says private keys and preshared keys must be files, because command line arguments are not considered private on most systems. If you only have the string, bash can fake a file with <(echo KEYSTRING), as the man page suggests. Passing /dev/null or another empty file removes the key again.

My umask 077 above is the same habit as for private keys, so the file is only readable by you. And one thing to watch: wg show wg0 dump prints the preshared key of every peer, together with its other details. Treat that output as a secret before you paste it into a forum post.

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 Table = off caddy reverse-proxy --from :2016 --to :9000 All Network and access tips (163) All topics

Link