GitHub refuses the SSH key you pasted
Key is invalid. You must supply a key in OpenSSH public key formatShort answer
GitHub only accepts the public half of an SSH key, pasted as one clean line. The error usually means you pasted the private key, copied the wrong file, broke the line while copying, or exported the key in a different format. Rebuild the public key from your private key with ssh-keygen -y and paste that.
Fix it fast
1Find out which cause you have
Print the file you are about to paste. A valid public key is a single line that starts with a key type such as ssh-ed25519 or ssh-rsa, and the file name ends in .pub.
cat ~/.ssh/id_ed25519.pub ssh-keygen -l -f ~/.ssh/id_ed25519.pub2Match what you see, then jump to its fix
- 1
The text you pasted spans many lines or starts with a BEGIN ... PRIVATE KEY header, or the file has no .pub ending.You pasted the private key, or the wrong fileFix - 2
The key looks right in the terminal but GitHub rejects it after you paste it from a wrapped window or a chat message.The copy added newlines or spacesFix - 3
The file starts with a line of dashes and BEGIN SSH2 PUBLIC KEY instead of a key type.The key is in another format, such as RFC4716Fix - 4
The line starts with ssh-dss.The key type is DSAFix
- 1
What does the error look like?
Key is invalid. You must supply a key in OpenSSH public key format
Cause 1 of 4
You pasted the private key, or the wrong file
1Check
List the key files. The one without .pub is the private key and must never leave your machine. GitHub wants the one ending in .pub.
ls -l ~/.ssh
head -n 1 ~/.ssh/id_ed255192Fix
If you lost the .pub file, rebuild it from the private key. Paste only that output.
ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pub3Verify
The file now holds one line. Copy it and add it under Settings, SSH and GPG keys.
cat ~/.ssh/id_ed25519.pubConfirmed by docs.github.com
Cause 2 of 4
The copy added newlines or spaces
1Check
GitHub warns against adding newlines or whitespace when copying. Terminal selection, email clients and chat tools often wrap or pad long lines.
wc -l ~/.ssh/id_ed25519.pub2Fix
Send the file to the clipboard with a command instead of selecting text by hand.
# macOS
pbcopy < ~/.ssh/id_ed25519.pub
# Windows PowerShell
cat ~/.ssh/id_ed25519.pub | clip3Verify
Paste into the Key field and save. The key appears in the list with a fingerprint.
ssh-keygen -l -f ~/.ssh/id_ed25519.pubConfirmed by docs.github.com
Cause 3 of 4
The key is in another format, such as RFC4716
1Check
ssh-keygen can import and export public keys in RFC4716, PKCS8 and PEM. RFC4716 is the default for both directions, and it is not what GitHub wants.
head -n 2 exported_key.pub2Fix
Convert it to the OpenSSH line with ssh-keygen -i.
ssh-keygen -i -f exported_key.pub > id_converted.pub3Verify
The output is one line starting with a key type, and ssh-keygen can read it.
ssh-keygen -l -f id_converted.pubConfirmed by man.openbsd.org
Cause 4 of 4
The key type is DSA
1Check
GitHub no longer supports DSA keys, and new ones cannot be added.
cut -d ' ' -f 1 ~/.ssh/id_dsa.pub2Fix
Generate a new key. Ed25519 is the type GitHub's own guide uses; RSA with 4096 bits is the option for old systems.
ssh-keygen -t ed25519 -C "your_email@example.com"
# old systems without Ed25519:
# ssh-keygen -t rsa -b 4096 -C "your_email@example.com"3Verify
Paste the new .pub file contents into GitHub.
cat ~/.ssh/id_ed25519.pubConfirmed by docs.github.com
How do I stop it coming back?
- Always paste from the file that ends in .pub, and keep the file without it private.
- Use pbcopy, clip or the GitHub CLI command gh ssh-key add instead of selecting text by hand.
- Generate Ed25519 keys on new machines.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Security
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fixSecurity
ASP.NET Core rejects the token before checking it: IDX12741, three segments expected
401 Unauthorized
IDX12741 means the string the API pulled out of the Authorization header is not shaped like a JWT: a signed token has three dot-separated parts and an encrypted one has five.
3 causes, each with a fixSecurity
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fix