"Key is invalid" message on GitHub

I came here because I had the same problem. From your question, I realized that I was copying the contents from the wrong file, without the .pub extension (it was my private key, i.e. the id_rsa file, which should be kept private at all times!)

From a MAC:

vi ~/.ssh/id_rsa.pub

Copy exactly from the end (with be the last letter of your email domain extension) of the block of characters to the beginning, which starts with ssh-rs ...

If it doesn't work, you are surely not copying properly.

It worked.

If you are on Windows, use notepad and copy-paste as described above.

I hope that helped.


Here are some steps that are not at all clear when copy/pasting your public key. (For the record, I used Putty Key Generator for my keys.)

  • On the first line, enter ssh-rsa.
  • Make sure you add one space after ssh-rsa
  • When you copy/paste the key into the Key textbox it should preserve the \n characters (x0A). If you are using Notepad on Windows, you won't see these new lines until you copy the text to Github.

Notice on this screenshot, there's a space after ssh-rsa (See the cursor.) The public key text also includes three \n characters, so you can see the public key text bumps down to the next line three times in the textbox.SSH RSA Key


I know this is question is a cpl years old now, but if someone in 2018 encounter this:

then below is a no-brainer:

my problem was I tried to copy the private key

id_rsa

instead of public key content

id_rsa.pub

as my SSH gitlab repository key, so after you:

ssh-keygen -t rsa -C "[email protected]" -b 4096

please remember about the .pub file extension to copy from:

  • OSX:

  pbcopy < ~/.ssh/id_rsa.pub

  • Linux:

  xclip -sel clip < ~/.ssh/id_rsa.pub

  • Windows PowerShell

  cat ~/.ssh/id_rsa.pub | clip


then paste it to your gitlab/github or other repository as your SSH key

this makes perfect sense, because you should always only share your public key, not the private one :)


I try several ways, but none of them helps(my os is ubuntu). Then I thought if I can print the content of ~/.ssh/id_rsa.pub by using command "more".

I sorry than I have no reputation to post images! when i have, i will post it!

Here is a url where you can see the image:

enter image description here

I copied the content from the command line, and it WORKED!!!


Someone suggested to use $ vi ~/.ssh/id_rsa.pub however it didn't work for me.

So instead of that , I used $ cat ~/.ssh/id_rsa.pub command on windows machine to print out on the terminal then copy it.