无法推送到 git 存储库 - 权限被拒绝

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

Cannot push to git repository - permission denied

gitgithubsshssh-keysssh-agent

提问by mc.suchecki

I have a following problem:

我有以下问题:

$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have already checked the connection doing this:

我已经检查了这样做的连接:

$ ssh -vT [email protected]

and output looks good, I was correctly authenticated.

并且输出看起来不错,我已正确验证。

While checking further, I noticed that:

在进一步检查时,我注意到:

$ ssh-add -l
The agent has no identities.

I have tried to run ssh-agent, but nothing changed:

我试图运行 ssh-agent,但没有任何改变:

$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-A1mhFqvqncuO/agent.766; export SSH_AUTH_SOCK;
SSH_AGENT_PID=767; export SSH_AGENT_PID;
echo Agent pid 767;
$ ssh-add -l
Could not open a connection to your authentication agent.

I am using Arch Linux. Any help would be strong appreciated! Thanks in advance!

我正在使用 Arch Linux。任何帮助将不胜感激!提前致谢!

Github diagnostic help here.

Github 诊断帮助在这里。

回答by NEO

I had the similar problem and my problem was solved by running the following command to add my key to the list of known keys:

我遇到了类似的问题,通过运行以下命令将我的密钥添加到已知密钥列表中解决了我的问题:

ssh-add ~/.ssh/id_rsa

Hope it solves yours too. ;)

希望它也能解决你的问题。;)

回答by DaoWen

If you haven't already read it, you should look through the GitHub help page for this error:

如果您还没有阅读它,您应该查看 GitHub 帮助页面以查找此错误:

Error: Permission denied (publickey)

错误:权限被拒绝(公钥)

Every time that I've had this problem, it was due to the last issue listed on that page: I didn't have the public key from my current workstation attached to my GitHub account. Of course, GitHub also provides instructions on how to attach your public key to your account.

每次我遇到这个问题时,都是由于该页面上列出的最后一个问题:我没有将当前工作站的公钥附加到我的 GitHub 帐户。当然,GitHub 还提供了有关如何将您的公钥附加到您的帐户的说明



tl;dr

tl;博士

Make sure your current public key is attached to your GitHub account.

确保您当前的公钥已附加到您的 GitHub 帐户。

回答by Sergio Belevskij

You need to do in your console (if you use an a putty ssh client):

您需要在控制台中执行以下操作(如果您使用腻子 ssh 客户端):

  1. Generate the keys, if keys not exist:

    cd ~/.ssh && ssh-keygen -lf ~/.ssh/id_rsa.pub
    
  1. 生成密钥,如果密钥不存在:

    cd ~/.ssh && ssh-keygen -lf ~/.ssh/id_rsa.pub
    

Don't forget password, entered at this step!

不要忘记密码,在这一步输入!

  1. Output your public key to screen:

    cd ~/.ssh && cat id_rsa.pub
    
  2. Copy this string by click and move a mouse pointer from begin output to end. No need to press Ctrl+ Vor any more keys.

  3. Log in your account on GitHub and add this public key to https://github.com/settings/ssh

  4. Now you can use your git locally.

  1. 将您的公钥输出到屏幕:

    cd ~/.ssh && cat id_rsa.pub
    
  2. 通过单击复制此字符串并将鼠标指针从开始输出移动到结束。无需按Ctrl+V或更多键。

  3. 在 GitHub 上登录您的帐户并将此公钥添加到https://github.com/settings/ssh

  4. 现在您可以在本地使用您的 git。

回答by squid314

I don't think this will solve your problem since you tested ssh -vT [email protected]directly and it worked, but you are using the ssh-agentimproperly. You need to run

我认为这不会解决您的问题,因为您ssh -vT [email protected]直接进行了测试并且它有效,但是您使用ssh-agent不当。你需要跑

$ eval `ssh-agent -s`
Agent pid 767
$ ssh-add -l
The agent has no identities.

This will evaluate the environment export commands and allow your ssh-addand sshcommands to communicate with the agent. Alternatively, you can ask the agent to start a shell, terminal, etc. and it will set up the proper environment:

这将评估环境导出命令并允许您的ssh-addssh命令与代理进行通信。或者,您可以要求代理启动 shell、终端等,它会设置正确的环境:

$ ssh-agent bash
$ ssh-add -l
The agent has no identities.

In this case, the shell is running as a child of the ssh-agentand the agent will shut down when the shell quits.

在这种情况下,shell 作为 的子进程运行,ssh-agent并且当 shell 退出时代理将关闭。

回答by Syed Shahul

I faced the same issue on my Ubuntu and then I realize that I am on sudomode, once I just access remotewithout sudoit went well.

我在我的 Ubuntu 上遇到了同样的问题,然后我意识到我处于sudo模式下,一旦我在remote没有sudo它的情况下访问就很顺利。

That's how I get rid if the issue, hope it may help.

这就是我摆脱问题的方式,希望它可以帮助。

回答by lujiwen

Permission denied (public key). I encountered this problem today, but I found a solution finally, and successfully solved my problem.

权限被拒绝(公钥)。我今天遇到了这个问题,但我终于找到了解决方案,并成功解决了我的问题。

Maybe you should verify following issues:

也许你应该验证以下问题:

  1. you have a github account
  2. git config your username and -mail
  3. generate a ssh-key pri/pub pair and add the public key to your git account, please check this may give you help: generating new ssh keyand cannot push git repository 'permission denied'
  4. check that ssh-key is successfully added: ssh -V [email protected]
  5. good luck!
  1. 你有一个 github 账户
  2. git config 你的用户名和 -mail
  3. 生成一个 ssh-key pri/pub 对并将公钥添加到您的 git 帐户,请检查这可能会给您帮助:生成新的 ssh 密钥并且无法推送 git 存储库“权限被拒绝”
  4. 检查 ssh-key 是否已成功添加: ssh -V [email protected]
  5. 祝你好运!

回答by Abdelilah El Aissaoui

In my case I had this problem with GitLab because I was working with non-default SSH key pair paths. @NEO 's answer works perfectly:

就我而言,我在 GitLab 上遇到了这个问题,因为我使用的是非默认的 SSH 密钥对路径。@NEO 的回答完美无缺:

ssh-add ~/.ssh/other_id_rsa

However, I had to do this everytime that I opened a new terminal.

但是,每次打开新终端时我都必须这样做。

To make this change permanent, you have to edit ~/.ssh/configand add the following:

要使此更改永久化,您必须编辑~/.ssh/config并添加以下内容:

Host gitlab.company.com
RSAAuthentication yes
IdentityFile ~/.ssh/config/private-key-filename

For more detailed info check gitlab's documentation.

有关更多详细信息,请查看gitlab 的文档