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