git 将 SSH 密钥添加到 GitHub 的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35612504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:49:18  来源:igfitidea点击:

Issue on adding SSH key to GitHub

gitgithubsshssh-keys

提问by Yu Xiong

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

我遇到了一个问题,似乎与 GitHub 使用的 SSH 密钥格式有关。我使用 Git Bash 生成了一个新的 SSH 密钥

$ ssh-keygen -t rsa -C "[email protected]"

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

然后,我将密钥复制到我的 GitHub 帐户页面设置中的 SSH 部分。但是,它附带了问题通知如下

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.

之后,我编辑了我的 SSH 密钥,以 ssh-rsa 开头,最后是我的电子邮件地址。然而,问题仍然存在。

Could anyone tell the solution about this? 

任何人都可以告诉解决方案吗? 

Thanks!

谢谢!

采纳答案by CodeWizard

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

只需按照这些步骤操作,您就可以立即设置 ssh 密钥:

  • 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/.sshdirectory (or Users/<your user>.sshunder windows), open it and copy the content

  • 生成一个新的 ssh 密钥(如果您已经有密钥,则跳过此步骤)
    ssh-keygen -t rsa -C "your@email"

  • home/.ssh目录(或Users/<your user>.sshWindows 下)中设置密钥后,打开它并复制内容



How to add sh key to github account?

如何将 sh 密钥添加到 github 帐户?

  • 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
  • 登录github账号
  • 点击右上角的牧场主(设置)
    github 账号设置
  • 点击 SSH keys
    ssh 密钥部分
  • 点击 Add ssh key
    添加ssh密钥
  • 粘贴您的密钥并保存

And you all set to go :-)

你们都准备好了:-)

回答by Kevin Burdett

ssh-keygenwill 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.

ssh-keygen将为您生成一对密钥,一个是私有的,一个是公共的。听起来你上传错了。GitHub 需要公钥,通常在这里:~/.ssh/id_rsa.pub

回答by bgerd

If you're using a mac and typing outgithub'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:

如果您使用的是 mac 并输入github 的说明(例如生成新的 SSH 密钥并将其添加到 ssh-agent,您可能正在输入并且仅使用 Tab 键(例如自动完成)来:

$ pbcopy < ~/.ssh/id_rsa

$ pbcopy < ~/.ssh/id_rsa

and not

并不是

$ pbcopy < ~/.ssh/id_rsa.pub

$ 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.

希望能节省你一些时间。

回答by shawlang

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

open ~/.ssh/id_rsa.pub,然后用编辑器打开它并将公钥复制到你的github

回答by sent-hil

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.

我遇到了同样的问题,结果证明这是因为评论中有 - 。Github 显然不喜欢 -,但 _ 没问题。

回答by Tin Torres

Another way to copy the public key to clipboard

另一种将公钥复制到剪贴板的方法

clip < ~/.ssh/id_rsa.pub