git GitHub:权限被拒绝(公钥)。致命:远端意外挂断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3617113/
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-10 09:00:23  来源:igfitidea点击:

GitHub: Permission denied (publickey). fatal: The remote end hung up unexpectedly

gitgithubpublic-key

提问by ziiweb

I have followed these instructions below to upload a project.

我已按照以下说明上传项目。

Global setup:

全局设置:

 Download and install Git
  git config --global user.name "Your Name"
  git config --global user.email [email protected]
  Add your public key


Next steps:

  mkdir tirengarfio
  cd tirengarfio
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin [email protected]:tirenga/tirenga.git
  git push origin master

But I get this error:

但我收到此错误:

Permission denied (publickey). fatal: The remote end hung up unexpectedly

权限被拒绝(公钥)。致命:远端意外挂断

采纳答案by Smundo

For me the problem was the execution of clone via sudo.

对我来说,问题是通过 sudo 执行克隆。

If you clone to a directory where you have user permission ( /home/user/git) it will work fine.

如果您克隆到您拥有用户权限 (/home/user/git) 的目录,它将正常工作。

(Explanation: Running a command as superuser will not work with the same public key as running a command as user. Therefore Github refused the connection.)

(说明:以超级用户身份运行命令不会使用与以用户身份运行命令相同的公钥。因此 Github 拒绝了连接。)

This solution requires a SSH key already to be set up: https://help.github.com/articles/generating-ssh-keys

此解决方案需要已设置 SSH 密钥:https: //help.github.com/articles/generate-ssh-keys

回答by ziiweb

I had to add my public key to github. https://help.github.com/articles/generating-ssh-keys

我不得不将我的公钥添加到 github。https://help.github.com/articles/generating-ssh-keys

回答by viprs

Yes, It's a public key Problem.I'm a windowsuser,and the page below help me resolve this problem.

是的,这是一个公钥问题。我是Windows用户,下面的页面帮助我解决了这个问题。

http://help.github.com/win-set-up-git/

http://help.github.com/win-set-up-git/

more precisely this link should be helpful

更准确地说,此链接应该会有所帮助

https://help.github.com/articles/error-permission-denied-publickey

https://help.github.com/articles/error-permission-denied-publickey

回答by Sergio Viera

after you created the RSA key pair, you must to add it to SSH using:

创建 RSA 密钥对后,您必须使用以下命令将其添加到 SSH:

ssh-add ~/.ssh/id_rsa

or wherever you created your rsa key pair.

或者在您创建 rsa 密钥对的任何地方。

回答by rahul_pratap

Type the following command using your username and repository name:

使用您的用户名和存储库名称键入以下命令:

git clone https://github.com/{user name}/{repo name}

in Ubuntu this works perfectly.

在 Ubuntu 中,这完美地工作。

回答by rafaeljuzo

I got a solution after a long time in tutorials.

经过很长时间的教程,我得到了解决方案。

I followed the github tutorial on this link -> https://help.github.com/articles/error-permission-denied-publickeyand I was able to connect in every step. But when I was trying to git push -u origin masterI got this error:

我按照此链接上的 github 教程进行操作 -> https://help.github.com/articles/error-permission-denied-publickey并且我能够在每一步进行连接。但是当我尝试git push -u origin master 时,我收到了这个错误:

Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights

权限被拒绝(公钥)。致命:无法从远程存储库读取。

请确保您拥有正确的访问权限

Thats how I`ve fixed it!!Go to the project directory using the Terminal and check it out

我就是这样修复的!!使用终端转到项目目录并查看

$git remote -v

You will get something like this:

你会得到这样的东西:

origin  ssh://[email protected]/yourGithubUserName/yourRepo.git (fetch)
origin  ssh://[email protected]/yourGithubUserName/yourRepo.git (push)

If you are using anything different then [email protected], open the config file on git directory by typing the command:

如果您使用的不是[email protected],请输入以下命令打开 git 目录中的配置文件:

vi .git/config

And configure the line

并配置线路

[remote "origin"]

url = ssh://[email protected]/yourGithubUserName/yourRepo.git

fetch = +refs/heads/*:refs/remotes/origin/

回答by Dan Power

In my case, I had to setup the public key for another user, as I already had one for my main user. once I switched users and performed the commands in the link above I was able to perform the setup for my test server without a problem.

就我而言,我必须为另一个用户设置公钥,因为我已经为我的主要用户设置了公钥。一旦我切换了用户并执行了上面链接中的命令,我就可以毫无问题地为我的测试服务器执行设置。

回答by Artem Russakovskii

Given that none of the answers here worked for me, I finally tracked down my issue connecting to Bitbucket (or Github, doesn't matter in this case) with ssh -vT [email protected].

鉴于这里的所有答案都不适合我,我终于通过 ssh -vT [email protected] 找到了连接到 Bitbucket(或 Github,在这种情况下无关紧要)的问题。

In my case, the failure was due to using a DSA key instead of RSA, and apparently my SSH client no longer allows that.

就我而言,失败是由于使用 DSA 密钥而不是 RSA,显然我的 SSH 客户端不再允许这样做。

debug1: Skipping ssh-dss key /c/Users/USER/.ssh/id_dsa for not in PubkeyAcceptedKeyTypes

debug1:跳过 ssh-dss 密钥 /c/Users/USER/.ssh/id_dsa 不在 PubkeyAcceptedKeyTypes 中

The solution was to add this to .ssh/config:

解决方案是将其添加到 .ssh/config:

Host *
    PubkeyAcceptedKeyTypes +ssh-dss

This elegantly appends the ssh-dss key type to all existing accepted public key types and after this was done, git can now ssh into Bitbucket no problem.

这优雅地将 ssh-dss 密钥类型附加到所有现有接受的公钥类型,完成后,git 现在可以 ssh 到 Bitbucket 没有问题。

回答by eold

I had this problem, but none of the solutions above worked. I could clone and fetch but couldn't push. Eventually, I figured out the problem was in the urlin my .git/config, it should be:

我遇到了这个问题,但上述解决方案都没有奏效。我可以克隆和获取但不能推送。最终,我发现问题出url在我的.git/config,它应该是:

[email protected]:<username>/<project>

(not ssh://github.com/<username>/<project>.gitor https://github.com/<username>/<project>.git).

(不是ssh://github.com/<username>/<project>.githttps://github.com/<username>/<project>.git)。

回答by paopao

My issue was that I was trying to give my ssh key a SPECIFIC NAMEevery time I entered ssh-keygenon my mac terminal.

我的问题是每次在我的 mac 终端上输入时,我都试图给我的 ssh 密钥一个特定的名称ssh-keygen

I solved the issue by just leaving the name that "ssh-keygen" generates = id_rsa. You'll end up with 2 keys in your .ssh folder on a mac, id_rsa, which is your private key, and the id_rsa.pub, which is your public key. Then I copied and saved the code from id_rsa.pubinto my GitHub account settings, and that was it. Problem solved.

我通过留下“ssh-keygen”生成的名称解决了这个问题 = id_rsa。您将在 Mac 上的 .ssh 文件夹中得到 2 个密钥id_rsa,这是您的私钥id_rsa.pub,而 是您的公钥。然后我将代码复制并保存id_rsa.pub到我的 GitHub 帐户设置中,就是这样。问题解决了。