Git 推送权限被拒绝(公钥)但已成功通过身份验证 [英] Git push permission denied (publickey) but successfully authenticated

查看:32
本文介绍了Git 推送权限被拒绝(公钥)但已成功通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 ssh 将我的提交推送到 github.我明白了

<块引用>

您已成功通过身份验证

运行 ssh -T git@github.com 命令后的消息,但是当我想推送我的提交时,我收到此错误:

<块引用>

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

请确保您拥有正确的访问权限和存储库存在.

我运行 ssh-add -l 命令然后我得到

4096 SHA256:SREQ0/2G0mT+UxUmpLWmkMramBcFxnl+onFyXgwFENk ~/.ssh/work2_rsa (RSA) 4096 SHA256:gKPZ1Hxzc6eZ/NsgnoPaXVaJs/NsgnoPaXVaJs/NsgnoPaXVaYsTydm.sgwFENk~/.ssh/work2_rsa

我运行 git remote -v 然后我得到

origin git@github.com:H-Ghadirian/UdacitySillySong.git (fetch)origin git@github.com:H-Ghadirian/UdacitySillySong.git(推送)傻宋 git@github.com:H-Ghadirian/UdacitySillySong.git (获取)SillySong git@github.com:H-Ghadirian/UdacitySillySong.git(推送)

我阅读了这篇文章.它与我的问题非常相似,但 sudo 没有解决我的问题.

我也运行 git push -u origin master 并得到同样的错误:

<块引用>

权限被拒绝(公钥).

我还阅读了权限被拒绝(公钥).致命:远程端意外挂断了 git pull,但我的公钥在 .ssh 文件夹中,这不是我的情况

我阅读了此页面:错误:权限被拒绝(公钥) 并检查所有.我错过了什么吗?

我该怎么办?

MacOS:Sierra

git 版本 2.13.5 (Apple Git-94)

作为 此链接 描述,我将config 文件添加到我的.ssh 文件夹并添加

主机 *AddKeysToAgent 是使用钥匙串 是身份文件 ~/.ssh/work2_rsa

给它.

解决方案

首先检查 git remote -v 返回的内容:

  • 它必须是您拥有的存储库或者您是其合作者
  • 它需要是正确的 ssh url git@github.com:<you>/<yourRepo.git>
    (而不是 https 一个就像你昨天的问题)

需要明确的是,您需要先在 GitHub 上创建远程存储库:推送到不存在的存储库会产生该错误.

通常,ssh url 不起作用意味着该 URL 没有按照 ssh 期望的方式编写.
由于 ~/.ssh/config 中的 ssh config 文件,ssh 可能需要不同的 URL.

<块引用>

我使用 sudo 运行命令并多次检查 repo.

您没有使用 sudi 运行 ssh git@github.com,这意味着您的推送命令也不需要 sudo.

I want to push my commits to github with ssh. I get

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:

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

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

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.

I also run git push -u origin master and get the same error :

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

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)

As this link describe,I add config file to my .ssh folder and add

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

to it.

解决方案

Check first what git remote -v does return:

  • 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>
    (And not an https one like in your question yesterday)

Just to be clear, you need to create the remote repo first on GitHub: pushing to a non-existing repo would generate that error.

Typically, an ssh url not working means said URL is not written the way ssh expects it.
And ssh might expect a different URL because of an ssh config file in ~/.ssh/config.

I run commands with sudo and check repo multiple times.

You did not run your ssh git@github.com with sudi, which means you also don't need sudo for your push commands.

这篇关于Git 推送权限被拒绝(公钥)但已成功通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆