ssh clone无法使用github

sab*_*ari 16 git github

我是Git和GitHub的新手.

我创建了一个新的存储库,并尝试在我的本地计算机上克隆.

它适用于https和git-readonly URL.也就是说,以下工作正常:

  • git clone https://github.com/npsabari/testrepo.git
  • git clone git://github.com/npsabari/testrepo.git

但是当我尝试时git clone git@github.com:npsabari/testrepo.git,它没有用.它给出了以下错误消息:

Cloning into 'testRepo'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)

然后我尝试了ssh git@github.com,但我得到了错误:

"Permission denied (publickey)."
Run Code Online (Sandbox Code Playgroud)

而不是欢迎消息.

我该怎么做才能解决这个问题?错误的原因是什么?

Mih*_*eac 17

根据GitHub 帮助,您获得错误与错误的SSH配置有关.请按照指示为GitHub设置SSH并进行相应的检查.


小智 8

您可以按照以下文档将密钥添加到ssh-agent https://help.github.com/en/articles/connecting-to-github-with-ssh

或者您可以运行以下命令暂时执行

ssh-agent bash -c 'ssh-add ~/.ssh/github_rsa; git clone git://github.com/npsabari/testrepo.git'


yel*_*w01 6

就我而言,问题在于我使用的机器是由存储库而不是我的用户进行身份验证的,尽管我的 GitHub 帐户注册了 ssh 密钥。

您可以检查谁通过了身份验证

ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)

发生这种情况是因为我将 ssh 密钥配置为我正在处理的存储库之一的部署密钥。