无法推送到 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
Cannot push to git repository - permission denied
提问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。任何帮助将不胜感激!提前致谢!
回答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 客户端):
Generate the keys, if keys not exist:
cd ~/.ssh && ssh-keygen -lf ~/.ssh/id_rsa.pub
生成密钥,如果密钥不存在:
cd ~/.ssh && ssh-keygen -lf ~/.ssh/id_rsa.pub
Don't forget password, entered at this step!
不要忘记密码,在这一步输入!
Output your public key to screen:
cd ~/.ssh && cat id_rsa.pub
Copy this string by click and move a mouse pointer from begin output to end. No need to press Ctrl+ Vor any more keys.
Log in your account on GitHub and add this public key to https://github.com/settings/ssh
Now you can use your git locally.
将您的公钥输出到屏幕:
cd ~/.ssh && cat id_rsa.pub
通过单击复制此字符串并将鼠标指针从开始输出移动到结束。无需按Ctrl+V或更多键。
在 GitHub 上登录您的帐户并将此公钥添加到https://github.com/settings/ssh
现在您可以在本地使用您的 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-agent
improperly. 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-add
and ssh
commands 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-add
和ssh
命令与代理进行通信。或者,您可以要求代理启动 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-agent
and 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 sudo
mode, once I just access remote
without sudo
it 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:
也许你应该验证以下问题:
- you have a github account
- git config your username and -mail
- 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'
- check that ssh-key is successfully added:
ssh -V [email protected]
- good luck!
- 你有一个 github 账户
- git config 你的用户名和 -mail
- 生成一个 ssh-key pri/pub 对并将公钥添加到您的 git 帐户,请检查这可能会给您帮助:生成新的 ssh 密钥并且无法推送 git 存储库“权限被拒绝”
- 检查 ssh-key 是否已成功添加:
ssh -V [email protected]
- 祝你好运!
回答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/config
and 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 的文档。