简体   繁体   English

Git 推送权限被拒绝(公钥)但成功通过身份验证

[英]Git push permission denied (publickey) but successfully authenticated

I want to push my commits to github with ssh. I get我想用 ssh 将我的提交推送到 github。我得到

You've successfully authenticated您已成功通过身份验证

message after run ssh -T git@github.com command but when I want to push my commits I get this error:运行ssh -T git@github.com命令后出现消息,但是当我想推送我的提交时,出现此错误:

Permission denied (publickey).权限被拒绝(公钥)。 fatal: Could not read from remote repository.致命:无法从远程存储库读取。

Please make sure you have the correct access rights and the repository exists.请确保您拥有正确的访问权限并且存储库存在。

I run ssh-add -l command and I get我运行ssh-add -l命令,我得到

4096 SHA256:SREQ0/2G0mT+UxUmpLWmkMramBcFxnl+onFyXgwFENk ~/.ssh/work2_rsa (RSA) 4096 SHA256:gKPZ1Hxzc6eZ/NsgnoPaJsGbdWgQV54bYAXaTym3PfY ~/.ssh/work3_rsa (RSA)

I run git remote -v and I get我运行git remote -v我得到

origin  git@github.com:H-Ghadirian/UdacitySillySong.git (fetch)
origin  git@github.com:H-Ghadirian/UdacitySillySong.git (push)
sillySong   git@github.com:H-Ghadirian/UdacitySillySong.git (fetch)
sillySong   git@github.com:H-Ghadirian/UdacitySillySong.git (push)

I read this post .我读了这篇文章 Its very similar to my issue but sudo didn't solve my problem.它与我的问题非常相似,但sudo没有解决我的问题。

I also run git push -u origin master and get the same error:我也运行git push -u origin master并得到同样的错误:

Permission denied (publickey).权限被拒绝(公钥)。

I also read Permission denied (publickey).我还阅读了权限被拒绝(公钥)。 fatal: The remote end hung up unexpectedly for git pull but my public key is in.ssh folder and thats not my case 致命:远程端意外挂断 git 拉但我的公钥在.ssh 文件夹中,那不是我的情况

I read this page: Error: Permission denied (publickey) and check all.我读了这个页面: 错误:权限被拒绝(公钥)并检查所有。 Did I miss something?我错过了什么?

What should I do?我应该怎么办?

MacOS : Sierra苹果操作系统:塞拉利昂

git version 2.13.5 (Apple Git-94) git 版本2.13.5 (Apple Git-94)

As this link describe,I add config file to my .ssh folder and add正如这个链接所描述的,我将config文件添加到我的.ssh文件夹中并添加

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/work2_rsa

to it.给它。

Check first what git remote -v does return: 首先检查git remote -v确实返回的内容:

  • it needs to be a repo you own or you are a collaborator of 它需要是你拥有的回购或者你是合作者
  • it needs to be the right ssh url git@github.com:<you>/<yourRepo.git> 它必须是正确的ssh url git@github.com:<you>/<yourRepo.git>
    (And not an https one like in your question yesterday ) (而不是昨天你问题中的https)

Just to be clear, you need to create the remote repo first on GitHub: pushing to a non-existing repo would generate that error. 为了清楚起见,您需要首先在GitHub上创建远程仓库:推送到不存在的仓库会产生该错误。

Typically, an ssh url not working means said URL is not written the way ssh expects it. 通常,ssh url不工作意味着所述URL不是按照ssh期望的方式编写的。
And ssh might expect a different URL because of an ssh config file in ~/.ssh/config . 由于~/.ssh/config中的ssh config文件,ssh可能会期望不同的URL。

I run commands with sudo and check repo multiple times. 我用sudo运行命令并多次检查repo。

You did not run your ssh git@github.com with sudi, which means you also don't need sudo for your push commands. 你没有用sudi运行你的ssh git@github.com ,这意味着你的push命令也不需要sudo

Double check your git config core.sshCommand is as intended.仔细检查您的 git 配置core.sshCommand是否符合预期。

I also ended up in this situation by copying my .gitconfig from C:\Users\<User>\.gitconfig to ~/.gitconfig in WSL, without realizing however that that copied along the path to an ssh executable.在这种情况下,我还通过将我的.gitconfigC:\Users\<User>\.gitconfig到 WSL 中的~/.gitconfig而结束了这种情况,但没有意识到沿着路径复制到 ssh 可执行文件。 In WSL that configuration shadowed the default;在 WSL 中,该配置隐藏了默认设置; the default should run instead.默认应该运行。

So I had to run所以我不得不跑

git config --global --unset core.sshCommand

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM