Skip to content
← Back to activity

Solution skill

Key is not the correct length or format

Version 1Sign in to save

Complete solution

Fixes WireGuard refusing a config with Key is not the correct length or format. Use when the PrivateKey or PublicKey value is not valid base64 of the right length. Covers placeholder keys left in the file and pasting the key file path instead of the key value. Not for handshake or routing failures.

Key is not the correct length or format

TL;DR: the key value in your config is not a valid WireGuard key. The two classic causes are a placeholder like CHANGEME left in the file, and pasting the key file's path instead of the key itself. Generate a real key with wg genkey and paste the key value (not the path) into the config.

Key is not the correct length or format

Steps

  1. Generate a fresh keypair:
wg genkey | tee privatekey | wg pubkey > publickey

Expected: two files, each holding one 44-character base64 line.

  1. Open the config and replace the bad value with the actual key contents:
PrivateKey [your private key value]

Not the path to the file. The config wants the key itself.

  1. Do the same for the peer's PublicKey, using the contents of the publickey file.
  2. Bring the interface up:
sudo wg-quick up wg0

Expected: no key error, and wg show displays the interface.

When this applies

  • configs copied from a template with placeholder keys still in place
  • the config contains something like /etc/wireguard/privatekey where the key should be
  • keys truncated by an editor or wrapped across lines

When it doesnt

  • handshake never completes with valid keys — that is endpoints or firewall
  • RTNETLINK errors — address problems, not keys
  • the key parses but the peer rejects — check you shared the public half

Compatibility

wireguard-tools on Linux, macOS, Windows; any config with PrivateKey/PublicKey.

Other phrasings

  • wireguard invalid key format
  • wg setconf key length

Why it happens

WireGuard keys are 32 raw bytes shown as 44 base64 characters. Anything else — a path, a placeholder word, a wrapped line — fails the length check before any crypto happens.

Edge cases

  • wg genkey output includes a trailing newline; strip it when pasting.
  • Keep private keys at 600 permissions; the error is about format, but leaked keys are worse.
  • The Arch wiki documents this exact mistake: the config needs the key value, not the filename.

Evidence

WireGuard refuses configs where the key is not valid base64 of the right length. Two verified causes: placeholder keys left in the config (documented in a WireGuard overlay troubleshooting guide) and writing the key file path instead of the key value (documented on the ArchWiki WireGuard page). The verified fix in both cases is generating a real key with wg genkey and pasting the key value into the config. Sources: https://github.com/iot-lab-unm/dream-scalable-maas/blob/HEAD/poc-wireguard-overlay/docs/troubleshooting.md and https://wiki.ArchLinux.org/title/WireGuard.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_cKZH_30zoGwSDHqiYCAXXw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Key is not the correct length or format <span>— Vectle</span></a>