Issue on adding SSH key to GitHub

2019-01-19 11:50发布

I have got an issue that seems about the format of SSH key used by GitHub. I used Git Bash to generate a new SSH key

$ ssh-keygen -t rsa -C "youremail@youremail.com"

Then, I copied the key to the SSH section in settings of my GitHub account page. However, it came with the issue notice as follow

Key is invalid. It must begin with 'ssh-ed25519', 'ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', or 'ecdsa-sha2-nistp521'. Check that you're copying the public half of the key

Following that, I edited my SSH key starting with ssh-rsa and my email address at the end. However, the issue is still there.

Could anyone tell the solution about this? 

Thanks!

6条回答
地球回转人心会变
2楼-- · 2019-01-19 11:59

open ~/.ssh/id_rsa.pub, then open it with editor and copy the public key to your github

查看更多
看我几分像从前
3楼-- · 2019-01-19 11:59

I ran into the same problem and it turns out it was due to there being - in the comment. Github apparently doesn't like -, _ is ok though.

查看更多
乱世女痞
4楼-- · 2019-01-19 12:07

Simply follow those steps and you will set up your ssh key in no time:

  • Generate a new ssh key (or skip this step if you already have a key)
    ssh-keygen -t rsa -C "your@email"

  • Once you have your key set in home/.ssh directory (or Users/<your user>.ssh under windows), open it and copy the content


How to add sh key to github account?

  • Login to github account
  • Click on the rancher on the top right (Settings)
    github account settigns
  • Click on the SSH keys
    ssh key section
  • Click on the Add ssh key
    Add ssh key
  • Paste your key and save

And you all set to go :-)

查看更多
Explosion°爆炸
5楼-- · 2019-01-19 12:09

ssh-keygen will generate you a pair of keys, one private and one public. It sounds like you uploaded the wrong one. GitHub wants the public key, typically here: ~/.ssh/id_rsa.pub.

查看更多
做个烂人
6楼-- · 2019-01-19 12:12

If you're using a mac and typing out github's instructions (e.g. Generating a new SSH key and adding it to the ssh-agent, you're probably typing and only tabbing (e.g. auto-completing) to:

$ pbcopy < ~/.ssh/id_rsa

and not

$ pbcopy < ~/.ssh/id_rsa.pub

With the former you're actually copying, and trying to paste your Private Key.

Hope that saves you some time.

查看更多
做自己的国王
7楼-- · 2019-01-19 12:19

Another way to copy the public key to clipboard

clip < ~/.ssh/id_rsa.pub
查看更多
登录 后发表回答