Key is invalid. you must supply a key in openssh public key format

I have followed the “Generating a new SSH key and adding it to the ssh-agent” and tried to follow the “Adding a new SSH key to your GitHub account” documentation. However when I try to add my new SSH key I get the following error: “key is invalid. you must supply a key in openssh public key format.”
I have looked through some of the other discussion threads and am at a loss. My key seems to be in the right format "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC87cGVRyVxUnw7JaSbgBJi6etAG8lSMQxq3isifGbT$sifGbTb [email]

Any suggestions? Let me know what other details to provide. Thanks!

That format looks correct to me, too. One thing I’d try is to leave of the description (what you abbreviated as “[email]”). If that doesn’t help I’d suspect a bug.

Hi @csperando, welcome to the community
The email at the end of your key is ok as comments are supported for that key type.
All ssh-ed25519 keys will always be 80 (68 removing the ssh-ed25519) characters in length (do not worry about the comment/email at the end).
Anyway on checking you keylength it has an extra 7 characters, which would explain the error message related to an unrecognised key format.

Could you try deleting and regenerating your key, and we can debug from there it f does not work.
ssh-keygen -t ed25519 -C "your_email@example.com"
Then try adding your SSH ‘Public’ Key part to your GitHub account (e.g. id_ed25519.pub, or replacing id_ed25519 in the command with the name of your private key file you used)

If you are still not working/the key length is incorrect, can you provide some more details on steps to reproduce, such as environment OS, are you using Git and what version, are you using Git Bash or Git CMD?

3 Likes

All ssh-ed25519 keys will always be 80 (68 removing the ssh-ed25519) characters in length

Thank you! Got it to work. Just a simple mistake on my part, like most errors. The terminal was only displaying 79 of the characters, and I miss-copied the key when checking the rest of the line. I did not realize that the ‘$’ character denotes some sort of line break.

1 Like

Please help me I have the same error I am using git bash on window
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACCO4k4/VekVHrQZxeRzErugun9TgAH7yz+sa/2mMDeOYQAAAJgBSPJKAUjy
SgAAAAtzc2gtZWQyNTUxOQAAACCO4k4/VekVHrQZxeRzErugun9TgAH7yz+sa/2mMDeOYQ
AAAEC2LNF1VVtTYMGeKBd52GrP04CAGL3sbb8k6kbL6Dtb1I7iTj9V6RUetBnF5HMSu6C6
f1OAAfvLP6xr/aYwN45hAAAAEHJqcmVnN0BnbWFpbC5jb20BAgMEBQ==
-----END OPENSSH PRIVATE KEY-----
The same I have added but it is not working

This is the wrong file. You should not see “-----BEGIN OPENSSH PRIVATE KEY-----”, only the characters of the key itself.

What you are looking for is id_ed25519.pub

What @csperando said is correct, but one important addition: You just published your private key. If you already authorized it anywhere (GitHub or otherwise) revoke that now, or anyone can log in as you. :warning:

Generate a new key and then try again with the .pub file. That file contains the public key. :slightly_smiling_face:

3 Likes

Inside the .ssh folder, you will find two keys named [id_ed25519 & id_ed25519.pub] The difference between these two key/files is, one is a private key-id and the other is a public key-id, you can notice that from their naming. The key ending with no extension is your private key -id use to enable the ssh-agent internally on your local machine or server while the other ending with .pub is your public key-id, while using the cat/less command to view it you will notice your Github email is added toward the ending part of the key contents this is the one you will use to add as an ssh key to your Github account through the GUI. Thanks.

1 Like

Hi All

Following this guide today and came across this error. I found the solution as suggested in the previos posts. Instead of following the guide, by doing:

clip < ~/.ssh/id_ed25519

Do this instead

clip < ~/.ssh/id_ed25519.pub

1 Like

@jcdevilleres Nice invent. I think the reason for the two keys is, the one without the .pub extension is meant for your private use. I.e if you want to activate on your machine internally. Then the one with .pub extension is meant for public use (activation), this is the reason why when one tries to use the private key for GitHub account activation on it’s never accepted. Thanks.