Key is invalid. You must supply a key in OpenSSH public key format: How to Fix It

Last updated November 11, 2026

TL;DR

Key is invalid. You must supply a key in OpenSSH public key format means the text you pasted is not a single-line OpenSSH public key.

Almost always one of these:

  • You pasted the private key instead of the .pub file
  • You pasted a PuTTY key, which saves public keys in the multi-line SSH2 format
  • The key picked up line breaks or lost characters while copying

Open your .pub file and check it is one line starting with ssh-ed25519 or ssh-rsa. If it is, copy it with the command below instead of selecting it by hand.

On this page

What you're seeing

GitHub shows this when you click Add SSH key under Settings, SSH and GPG keys:

Key is invalid. You must supply a key in OpenSSH public key format

Older GitHub API clients report the same problem as key is invalid. It must begin with 'ssh-rsa' or 'ssh-dss'. Other services word it differently but mean the same thing: Bitbucket says That SSH key is invalid, and Azure DevOps rejects keys with extra spaces or line breaks in the Key Data field.

What a valid OpenSSH public key looks like

One line, with up to three parts separated by spaces: the key type, the key itself in base64, and an optional comment.

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGq7bZcqTnUWm7S9d1tRZ0kGfXwQx4Lz6sV3pN8yHcJe you@laptop

The first word is the key type. GitHub accepts ssh-ed25519, ssh-rsa, ecdsa-sha2-nistp256 (and the 384 and 521 variants), plus the hardware security key types [email protected] and [email protected]. GitHub no longer accepts DSA (ssh-dss) keys.

Anything that starts with -----BEGIN, or ---- BEGIN SSH2 PUBLIC KEY ----, or spans several lines, is not in OpenSSH public key format.

What's causing this error

  1. You pasted the private key. A private key starts with -----BEGIN OPENSSH PRIVATE KEY----- and lives in the file without .pub. Never paste it anywhere; the public half is the .pub file.
  2. You pasted a PuTTY key. PuTTYgen's Save public key button writes the SSH2 format (RFC 4716), which spans several lines and starts with ---- BEGIN SSH2 PUBLIC KEY ----. A .ppk file holds the private key and is not accepted either.
  3. You pasted a PEM public key. Keys exported by OpenSSL or some cloud consoles start with -----BEGIN PUBLIC KEY-----. Same key, different wrapping.
  4. The key broke while copying. A text editor or terminal wrapped the long line, or the selection missed the first or last characters.
  5. You pasted the fingerprint. SHA256:... is a fingerprint that identifies the key; it is not the key.
  6. The .pub file is empty or the key type is not supported, such as Ed448.

How to fix it

1. Copy the right file with a command

Print or copy the public key straight from the file so nothing gets wrapped or cut. Replace id_ed25519 with id_rsa or id_ecdsa if that is your key.

$ cat ~/.ssh/id_ed25519.pub
# or straight to the clipboard:
$ xclip -sel clip < ~/.ssh/id_ed25519.pub

Paste it into the Key box, not the Title box, and check it is still one line.

2. Rebuild the public key from your private key

If the .pub file is missing or damaged, ssh-keygen can derive it from the private key:

ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pub

It asks for the passphrase if the key has one. If you have no key at all, create one with ssh-keygen -t ed25519 -C "[email protected]", or use the SSH key generator.

3. Convert a PuTTY key

In the PuTTYgen window, load your .ppk with Load, then copy the text from the box labelled Public key for pasting into OpenSSH authorized_keys file. That box already holds the one-line OpenSSH format. Do not use Save public key, and do not use Conversions, Export OpenSSH key, which exports the private key.

On Linux or macOS with the putty-tools package:

puttygen key.ppk -O public-openssh -o key.pub

Plain -O public gives you the SSH2 format again, so use public-openssh. To move a PuTTY key over to OpenSSH entirely, the PPK to PEM converter walks through it.

4. Convert an SSH2 or PEM public key

If you already have a public key in the wrong wrapping, ssh-keygen converts it to the OpenSSH one-liner:

# SSH2 / RFC 4716 (---- BEGIN SSH2 PUBLIC KEY ----)
ssh-keygen -i -f key.pub

# PEM (-----BEGIN PUBLIC KEY-----)
ssh-keygen -i -m PKCS8 -f key.pem

Both print the converted key, ready to paste.

5. Check the key before you paste it

ssh-keygen -l -f ~/.ssh/id_ed25519.pub

A valid public key prints its size, fingerprint and type, for example 256 SHA256:... you@laptop (ED25519). An error here means the file itself is broken. The SSH key validator does the same check in your browser and names the format it found.

Common edge cases

What you seeWhat is actually wrong
Works for one key, fails for anotherThe failing key is DSA (ssh-dss) or another type GitHub no longer accepts. Generate an Ed25519 key.
Key starts with ssh-rsa but still failsA line break or missing character crept in. Copy it again with the command for your OS.
You copied from PuTTYgen and it failsYou used Save public key (SSH2 format). Copy from the "Public key for pasting into OpenSSH authorized_keys file" box instead.
Pasted text starts with SHA256:That is the fingerprint. Paste the full contents of the .pub file.
Error on Azure DevOpsAzure DevOps only accepts RSA keys, and trailing spaces or newlines break it. Paste an ssh-rsa key on one line.
Key was accepted but SSH still failsThe upload worked; the login problem is separate. See SSH Permission Denied (publickey).

Related errors