Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Key is invalid" message on GitHub

People also ask

How do I fix my SSH key in GitHub?

In terminal enter this command with your ssh file name pbcopy < ~/. ssh/id_rsa. pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

How do I create a GitHub key?

Login to github.com and bring up your account settings by clicking the tools icon. Select SSH Keys from the side menu, then click the Add SSH key button. Name your key something whatever you like, and paste the contents of your clipboard into the Key text box. Finally, hit Add key to save.


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.


If you have indeed copied the content of your id_rsa.pub key (in one continuous line), the result should look like (from The GitHub ssh help page):

ssh key

The OP louism confirms a copy-paste issue:

  • For a very obscure reason, copy-pasting from emacs removed the \n after ssh-rsa, and that was causing the problem.
  • Copy-pasting from vi solved the problem.