WireGuard config errors: Line unrecognized, Key is not the correct length or format

Line unrecognized means the program doesn't know this line or it stands in the wrong section. If it names Jc, S1 or H1, it is an AmneziaWG file and plain WireGuard won't open it. If it names Address or DNS, the file was given to wg instead of wg-quick. “Key is not the correct length or format” means the key isn't 44 characters ending in =: a placeholder, a cut or a path stands in its place.

Updated

WireGuard config check: fields, mistakes and a QR code

What Veli does with such a file. In Veli the .conf goes into Profiles → Add, as a file or as pasted text, and a line under the field says what it is: WireGuard or AmneziaWG.

Download Veli for free
On this page

The same mistake in different apps

Every WireGuard app reads the same format, but each words its refusals in its own way. On Linux the line is followed by Configuration parsing error, and spaces are gone from it: Jc = 4 is printed as Jc=4.

  • An unknown line in [Interface]

    Linux, wg and wg-quickLine unrecognized: `Jc=4'

    WindowsInvalid key for [Interface] section: "jc"

  • An unknown line in [Peer]

    Linux, wg and wg-quickLine unrecognized: `DNS=1.1.1.1'

    WindowsInvalid key for [Peer] section: "dns"

  • A line above the first section

    Linux, wg and wg-quickLine unrecognized

    WindowsLine must occur in a section

  • A wrong key

    Linux, wg and wg-quickKey is not the correct length or format

    WindowsKeys must decode to exactly 32 bytes, or Invalid key

  • No private key

    Linux, wg and wg-quickThe file is taken, the handshake never happens

    WindowsAn interface must have a private key

  • A peer without a key

    Linux, wg and wg-quickA peer is missing a public key

    WindowsAll peers must have public keys

  • Endpoint without a port

    Linux, wg and wg-quickUnable to find port of endpoint

    WindowsMissing port from endpoint

  • A bad address in AllowedIPs

    Linux, wg and wg-quickAllowedIP is not in the correct format, or Unable to parse IP address

    WindowsInvalid IP address

  • The file's name

    Linux, wg and wg-quickThe config file must be a valid interface name, followed by .conf

    WindowsTunnel name is not valid

  • macOS: Interface contains unrecognized key ‘Jc’, Peer contains unrecognized key ‘DNS’, Private key is invalid, Public key is invalid. Below the first one the app lists the keys it knows.
  • Android: Unknown attribute in Interface, Unknown attribute in Peer, Incorrect key length, Bad characters in key, Invalid name for the file's name.

Line unrecognized: the line tells the cause

Linux: Terminal (bash)
sudo bash -c 'wg setconf wg0 <(wg-quick strip wg0)'

strip leaves out the lines only wg-quick knows (Address, DNS, PostUp and others) and hands the rest to wg. The interface must exist.

Linux or macOS: Terminal
head -c 3 wg0.conf | od -An -tx1

ef bb bf is a BOM, ff fe is UTF-16. A clean file starts with 5b (the bracket) or 23 (the # sign).

Linux: Terminal
sed -i '1s/^\xEF\xBB\xBF//' wg0.conf

Removes the BOM. Windows line endings don't have to be fixed: they count as spaces.

  • Jc, Jmin, Jmax, S1, H1, I1, HeaderProtectionKey

    CauseAn AmneziaWG file in a WireGuard app

    What to doOpen it in an AmneziaWG client. Deleting the lines doesn't help: the server expects changed packets

  • Address, DNS, MTU, Table, PostUp

    CauseThe file was given to wg setconf, or the line stands under [Peer]

    What to dowg-quick up, or wg setconf with wg-quick strip; move the line under [Interface]

  • Endpoint, PublicKey, AllowedIPs

    Cause[Peer] is missing above them, or misspelled

    What to doAdd [Peer], exactly so

  • PrivateKey or ListenPort

    CauseThey stand under [Peer]

    What to doMove them under [Interface]

  • [Interface] itself

    CauseInvisible characters in front: the file was saved as UTF-8 with BOM or UTF-16

    What to doSave it as plain UTF-8, or use the command below

  • [Peers], [Server]

    CauseThere are only two sections, [Interface] and [Peer]

    What to doFix the heading

  • PrivateKey with a typo, such as PrivatKey

    CauseThe name is checked to the letter; capitals don't matter

    What to doFix the name

  • SaveConfig or FwMark, on Windows or a phone

    CauseThese are Linux lines, other apps don't know them

    What to doDelete the line

  • PostUp, PreUp, on macOS, iOS or Android

    CauseThese apps run no commands

    What to doDelete the line

Which app takes which line

A file that works on a server with wg-quick may be refused by a phone. This is what the code of each official app accepts in [Interface] besides PrivateKey, Address, DNS, MTU and ListenPort, which all of them know.

  • PreUp, PostUp, PreDown, PostDown

    wg-quickRuns them

    WindowsAccepts; runs only with DangerousScriptExecution in the registry

    macOS and iOSRefuses the file

    AndroidRefuses the file

  • Table

    wg-quickYes

    WindowsYes

    macOS and iOSRefuses the file

    AndroidRefuses the file

  • FwMark, SaveConfig

    wg-quickYes

    WindowsRefuses the file

    macOS and iOSRefuses the file

    AndroidRefuses the file

  • IncludedApplications, ExcludedApplications

    wg-quickRefuses the file

    WindowsRefuses the file

    macOS and iOSRefuses the file

    AndroidYes

  • Jc, S1, H1 and other AmneziaWG lines

    wg-quickRefuses the file

    WindowsRefuses the file

    macOS and iOSRefuses the file

    AndroidRefuses the file

Key is not the correct length or format

A WireGuard key is 32 bytes written in base64: always 44 characters, the last one =. The program counts exactly that, so anything else gives the error, and the text after it is what it read in place of a key. Windows says the same as Keys must decode to exactly 32 bytes or Invalid key: illegal base64 data at input byte.

Linux: Terminal
sudo awk '/Key *=/ {sub(/^[^=]*= */, ""); print length($0)}' /etc/wireguard/wg0.conf

The length of each key in the file, in order. Every number must be 44: trailing spaces count too, so a 45 may be just a space.

Linux, macOS or Windows with wg: terminal
echo "KEY" | wg pubkey

KEY is the key being checked. A line of 44 characters in reply: the format is right. An error: it isn't. For a private key the reply is its public key.

  • A placeholder was left in: <client private key> or CLIENT_KEY from an example.
  • The = was cut off. A double click in a terminal often selects a key without its last character.
  • A path instead of a key. In a file the key itself stands after PrivateKey. A path is what the command takes: wg set wg0 private-key /etc/wireguard/server.key.
  • The words (hidden). wg show hides private keys; the real one is in the file or in sudo wg show wg0 private-key.
  • Quotes or brackets around it. The format has none.
  • Keys of another kind: an SSH key, a Reality key (43 characters, no =), a hex string of 64 characters.
  • wg: Key is not the correct length or format with nothing after it comes from wg pubkey: it was given an empty line or the wrong file.

Tunnel name is not valid

The tunnel gets its name from the file. On Linux and Android it is up to 15 characters, on Windows up to 32: Latin letters, digits and _ = + . -. Spaces, brackets and other alphabets are out, so a second download named wg0 (1).conf is refused, and so is a file named after a city in Cyrillic. On Windows names such as con, nul and com1 are taken by the system. Rename the file and import it again.

Other messages about values

  • Warning: AllowedIP has nonzero host part is a warning, not an error: 10.8.0.2/24 is read as the network 10.8.0.0/24. For one device write /32.
  • Persistent keepalive interval is neither 0/off nor 1-65535: one number of seconds is needed. A range such as 22-30 is from AmneziaWG 3.
  • Two commas in a row (Windows): an extra comma in AllowedIPs, Address or DNS, at the end of the line too.
  • Brackets must contain an IPv6 address (Windows): an IPv6 address in Endpoint goes in square brackets, [2001:db8::1]:51820.
  • Invalid MTU (Windows): from 576 to 65535.
  • Name or service not known: the name in Endpoint doesn't exist; put the server's IP there.

Find it faster

The WireGuard config checker on this site, /tools/wireguard-check/, reads the file in the browser and lists every mistake with its line: keys, sections, Endpoint, AllowedIPs, AmneziaWG lines. It can't see one thing, whether the keys belong to each other: a file may be flawless, and the handshake still doesn't happen because the server doesn't know the client's key. That is another guide, on Handshake did not complete.

Sources

How we write and check

In Veli

What Veli does with such a file

In Veli the .conf goes into Profiles → Add, as a file or as pasted text, and a line under the field says what it is: WireGuard or AmneziaWG. AmneziaWG files of versions 1 and 2.0 connect as they are, and lines Veli doesn't need, such as PostUp, Table or SaveConfig, are skipped instead of refused; commands from a file are never run. For a profile it needs a PrivateKey, the server's PublicKey and an Endpoint.

A mistake in a key or a number that the app can't see when adding shows in Profiles on a computer: the check makes a real handshake, and next to such a server there is a word instead of a time, with the reason on hover. To take the file apart line by line, there is the checker at /tools/wireguard-check/; it works in the browser, and the file isn't sent anywhere.

FAQ

What does Line unrecognized: Jc mean?

The file is for AmneziaWG, and it was opened in plain WireGuard. Import it into a client that knows AmneziaWG.

Why does wg setconf say Line unrecognized: Address?

Address, DNS, MTU and PostUp are wg-quick's lines, wg doesn't know them. Use wg-quick up, or give wg the output of wg-quick strip.

How long is a WireGuard key?

44 characters of base64 with = at the end, which is 32 bytes. The private, public and preshared keys all look the same.

Does WireGuard on Windows run PostUp?

It accepts the line and runs it only if an administrator has turned on DangerousScriptExecution in the registry. The macOS, iOS and Android apps refuse such a file.

Can I convert an AmneziaWG config to WireGuard?

Not by editing the file: the server expects AmneziaWG's packets. Only a file whose only extra lines are Jc, Jmin and Jmax works after deleting them.

One window for WireGuard and AmneziaWG files

Drop the .conf into Veli: it tells WireGuard from AmneziaWG by itself, skips lines it doesn't need and never runs commands from a file. Free, for four systems.