Git 著名的“错误:对用户的 .git 权限被拒绝”

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

Git's famous "ERROR: Permission to .git denied to user"

gitsshgithub

提问by meder omuraliev

I have tried googling and read through https://help.github.com/en/articles/connecting-to-github-with-sshand various, various guides. I am unable to git push -u origin masteror git push origin master( the same command ).

我试过谷歌搜索并通读https://help.github.com/en/articles/connecting-to-github-with-ssh和各种不同的指南。我无法git push -u origin mastergit push origin master(相同的命令)。

I've had my git account for at least 2 or so years. I've successfully been able to create repos and push -u origin masterfine on my laptop but on this desktop I'm having issues.

我的 git 帐户至少已有 2 年左右了。我已经成功地push -u origin master在我的笔记本电脑上创建了 repos 并且很好,但是在这个桌面上我遇到了问题。

Here's what I tried:

这是我尝试过的:

1.I have setup my git user name

1.我已经设置了我的 git 用户名

2.I have setup my git user email

2.我已经设置了我的 git 用户电子邮件

3.I have uploaded the contents of my /home/meder/.ssh/id_rsa.pub to github's account page. I have verified I did not paste any whitespace

3.我已经把我的/home/meder/.ssh/id_rsa.pub的内容上传到github的账号页面。我已经确认我没有粘贴任何空格

4.I have created a ~/.ssh/config with these contents:

4.我用这些内容创建了一个 ~/.ssh/config :

  Host github.com
  User git
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa

I have chmodded the .ssh to 700, id_rsa 600

我已将 .ssh 修改为 700,id_rsa 600

5.I have added the properremote origin without making typos: git remote add origin [email protected]:medero/cho.git

5.我添加了正确的远程源,没有打错字git remote add origin [email protected]:medero/cho.git

6.To confirm #5, here is my .git/config. The directory is correctand not another directory:

6.确认#5,这是我的.git/config。该目录是正确的,而不是另一个目录:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = [email protected]:medero/cho.git

7.ssh [email protected] -vgives me a successful Authentication

7.ssh [email protected] -v给我一个成功的认证

8.One weird thing is, the username which it greets me with has tappended to it. My github username is medero, not medert.

8.一件奇怪的事情是,它向我打招呼的用户名t附加在它上面。我的 github 用户名是medero,不是medert

Hi mederot! You've successfully authenticated, but GitHub does not provide shell access.

嗨,梅德罗!您已成功通过身份验证,但 GitHub 不提供 shell 访问。

9.I am notbehind a proxy or firewall

9.不在代理或防火墙后面

10.The key is offered, heres the output from -v:

10.提供了密钥,以下是输出-v

debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/meder/.ssh/known_hosts:58
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/meder/.ssh/id_rsa
debug1: Remote: Forced command: gerve mederot
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: { some stuff, dont know if i should share it

debug1: Remote: Forced command: gerve mederot
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/meder/.ssh/known_hosts:58
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/meder/.ssh/id_rsa
debug1: Remote: Forced command: gerve mederot
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: { some stuff, dont know if i should share it

debug1: Remote: Forced command: gerve mederot
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).

11.Here are the commands I used

11.这是我使用的命令

mkdir cho
git init
touch README
git add README
git commit -m 'test'
git remote add origin [email protected]:medero/cho.git
git push -u origin master

12.I don't want to create a new SSH key.

12.我不想创建新的 SSH 密钥。

13.If I git clone using ssh and make an edit, commit, and git push, I get the same exact thing.

13.如果我使用 ssh git clone 并进行编辑、提交和 git push,我会得到完全相同的结果。

14.Here's the actual error:

14.这是实际的错误:

$ git push
ERROR: Permission to medero/cho.git denied to mederot.
fatal: The remote end hung up unexpectedly

15.I have setup my github username and github token:

15.我已经设置了我的 github 用户名和 github 令牌:

$ git config --global github.user medero $ git config --global github.token 0123456789yourf0123456789tokenSets the GitHub token for all git instances on the system

$ git config --global github.user medero $ git config --global github.token 0123456789yourf0123456789token 为系统上的所有 git 实例设置 GitHub 令牌

16.I have confirmed my github username is NOT mederotand my github token IS CORRECT per my account page ( validated first 2 chars and last 2 chars ).

16.我已经确认我的 github 用户名不是mederot,我的 github 令牌是正确的每个我的帐户页面(验证前 2 个字符和最后 2 个字符)。

17.To confirm #16, ~/.gitconfig contains

17.确认#16, ~/.gitconfig 包含

[github]
    token = mytoken...
    user = medero

18.I did ssh-key add ~/.ssh/id_rsaif that's even necessary...

18.ssh-key add ~/.ssh/id_rsa如果有必要的话,我做了……



THEORIES:



理论:

I suspect there's something fishy because when I get ssh authenticated, the user greeting is mederotand not medero, which is my acct. Could something in my github account possibly be incorrectly cached?

我怀疑有些可疑,因为当我通过 ssh 身份验证时,用户问候语是mederot而不是medero,这是我的帐户。我的 github 帐户中的某些内容可能被错误地缓存了吗?

I also suspect some local ssh caching weirdness because if i mv ~/.ssh/id_rsa KAKAand mv ~/.ssh/id_rsa.pub POOPOO, and do ssh [email protected] -v, it still Authenticates me and says it serves my /home/meder/.ssh/id_rsa when I renamed it?! It has to be cached?!

我还怀疑一些本地 ssh 缓存的奇怪之处,因为如果 imv ~/.ssh/id_rsa KAKAmv ~/.ssh/id_rsa.pub POOPOO, 并且 do ssh [email protected] -v,它仍然对我进行身份验证并说它在我重命名时为我的 /home/meder/.ssh/id_rsa 服务?!它必须被缓存?!

采纳答案by Mark Longair

In step 18, I assume you mean ssh-add ~/.ssh/id_rsa? If so, that explains this:

在第 18 步中,我假设您的意思是ssh-add ~/.ssh/id_rsa?如果是这样,这就解释了这一点:

I also suspect some local ssh caching weirdness because if i mv ~/.ssh/id_rsa KAKA and mv ~/.ssh/id_rsa.pub POOPOO, and do ssh [email protected] -v, it still Authenticates me and says it serves my /home/meder/.ssh/id_rsa when I renamed it?! It has to be cached?!

我也怀疑一些本地 ssh 缓存的奇怪之处,因为如果我 mv ~/.ssh/id_rsa KAKA 和 mv ~/.ssh/id_rsa.pub POOPOO,并执行 ssh [email protected] -v,它仍然对我进行身份验证并说它提供服务我重命名时的 /home/meder/.ssh/id_rsa ?!它必须被缓存?!

... since the ssh-agentis caching your key.

...因为ssh-agent正在缓存您的密钥。

If you look on GitHub, there is a mederotaccount. Are you sure that this is nothing to do with you? GitHub shouldn't allow the same SSH public key to be added to two accounts, since when you are using the [email protected]:...URLs it's identifying the user based on the SSH key. (That this shouldn't be allowed is confirmed here.)

如果你在 GitHub 上看,有一个mederot帐户。你确定这与你无关?GitHub 不应允许将相同的 SSH 公钥添加到两个帐户,因为当您使用[email protected]:...URL 时,它会根据 SSH 密钥识别用户。(这里确认这不应该被允许。)

So, I suspect (in decreasing order of likelihood) that one of the following is the case:

因此,我怀疑(按可能性降序)是以下情况之一:

  1. You created the mederot account previously and added your SSH key to it.
  2. Someone else has obtained a copy of your public key and added it to the mederot GitHub account.
  3. There's a horrible bug in GitHub.
  1. 您之前创建了 mederot 帐户并将您的 SSH 密钥添加到其中。
  2. 其他人已获得您的公钥副本并将其添加到 mederot GitHub 帐户。
  3. GitHub 中有一个可怕的错误。

If 1 isn't the case then I would report this to GitHub, so they can check about 2 or 3.

如果 1 不是这种情况,那么我会将其报告给 GitHub,以便他们可以检查大约 2 或 3。

More :

更多的 :

ssh-add -l check if there is more than one identify exists if yes, remove it by ssh-add -d "that key file"

ssh-add -l 检查是否存在多个标识,如果是,则通过 ssh-add -d “那个密钥文件”将其删除

回答by Alice Chan

After Googling for few days, I found this is the only question similar to my situation.

谷歌搜索了几天后,我发现这是唯一与我的情况类似的问题。

However, I just solved the problem! So I am putting my answer here to help anyone else searching for this issue.

然而,我刚刚解决了这个问题!所以我把我的答案放在这里是为了帮助其他人搜索这个问题。

Here is what I did:

这是我所做的:

  1. Open "Keychain Access.app"(You can find it in Spotlight or LaunchPad)

  2. Select "All items"in Category

  3. Search "git"

  4. Delete every old & strange item

  5. Try to Push again and it just WORKED

  1. 打开“Keychain Access.app”(您可以在 Spotlight 或 LaunchPad 中找到它)

  2. 在类别中选择“所有项目”

  3. 搜索“git”

  4. 删除所有旧的和奇怪的项目

  5. 尝试再次推动,它就起作用了

回答by FAHID

If problem is coming on windows then remove the Credentials from the Windows history.

如果 Windows 出现问题,则从 Windows 历史记录中删除凭据。

  • Go to Credential Manager
  • Go to Windows Credentials
  • Delete the entries under Generic Credentials
  • Try connecting again.This time , it should prompt you for the correct username and password.
  • 转到凭据管理器
  • 转到 Windows 凭据
  • 删除通用凭据下的条目
  • 再次尝试连接。这一次,它应该提示您输入正确的用户名和密码。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

remove credentials from git

从 git 中删除凭据

回答by leanne

On Mac, if you have multiple GitHub logins and are notusing SSH, force the correct login by using:

在 Mac 上,如果您有多个 GitHub 登录名且未使用 SSH,请使用以下命令强制正确登录:

git remote set-url origin https://[email protected]/username/repo-name.git

This also works if you're having issues pushing to a private repository.

如果您在推送到私有存储库时遇到问题,这也适用。

回答by Sarvesh

Its due to a conflict.

是因为冲突。

Clear all keys from ssh-agent

从 ssh-agent 清除所有密钥

ssh-add -d ~/.ssh/id_rsa
ssh-add -d ~/.ssh/github

Add the github ssh key

添加github ssh密钥

ssh-add   ~/.ssh/github

It should work now.

它现在应该可以工作了。

回答by Deepak Bhatta

I am using Mac and the issue is solved by deleting github record from keychain access app: Here is what i did:

我正在使用 Mac,问题是通过从钥匙串访问应用程序中删除 github 记录来解决的:这是我所做的:

  1. Open "Keychain Access.app" (You can find it in Spotlight orLaunchPad)
  2. Select "All items" in Category
  3. Search "git"
  4. Delete every old & strange items Try to Push again and it just WORKED
  1. 打开“Keychain Access.app”(您可以在 Spotlight 或LaunchPad 中找到它)
  2. 在类别中选择“所有项目”
  3. 搜索“git”
  4. 删除所有旧的和奇怪的项目尝试再次推送,它只是有效

Above steps are copied from @spyar for the ease.

为方便起见,以上步骤是从@spyar 复制的。

回答by thuanle

I find the solution is the same as @spyar provide which is the Keychain Accessapp stored the old username.

我发现解决方案与@spyar 提供的相同,后者是存储旧用户名的钥匙串访问应用程序。

There are 2 solutions for this situation:

这种情况有两种解决方案:

  1. Delete the info in Keychain Accessby
    • Open Keychain Accessapp
    • Search for github
    • Delete corresponding credentials
  1. 删除信息钥匙串访问通过
    • 打开钥匙串访问应用程序
    • 搜索github
    • 删除相应的凭据

Or

或者

  1. If you use want to use ssh key. You just change your Repo url from https
  1. 如果你使用想使用ssh key。您只需从 https 更改您的 Repo url

https://github.com/username/repo.git

https://github.com/username/repo.git

into

进入

[email protected]:username/repo.git

[email protected]:用户名/repo.git

Hope this helps.

希望这可以帮助。

回答by PhilVarg

I recently ran into this issue for on old repo on my machine that had been pushed up using https. steps 5 and 6 solved my issue by re-setting the remote url for my repo from using the https url to the ssh url

我最近在使用 https 推送的机器上的旧仓库上遇到了这个问题。步骤 5 和 6 通过将我的 repo 的远程 url 从使用 https url 重新设置为 ssh url 解决了我的问题

checking the remote is using the https url

检查遥控器是否使用 https url

> git remote -v
origin  https://github.com/ExampleUser/ExampleRepo.git (fetch)
origin  https://github.com/ExampleUser/ExampleRepo.git (push)

then re-setting the origin to use the ssh url

然后重新设置原点以使用 ssh url

> git remote set-url origin [email protected]:ExampleUser/ExampleRepo.git

verifying new remote

验证新遥控器

> git remote -v
origin  [email protected]:ExampleUser/ExampleRepo.git (fetch)
origin  [email protected]:ExampleUser/ExampleRepo.git (push)

could now successfully git push -u origin

现在可以成功 git push -u origin

i'm still not sure what setting i would have changed that might have caused the push to fail when the remote is https but this was the solution to my issue

我仍然不确定当远程是 https 时我会更改哪些设置可能导致推送失败,但这是我问题的解决方案

回答by Perth Charles

I had the same problem as you. After a long time spent Googling, I found out my error was caused by multiple users that had added the same key in their accounts.

我和你有同样的问题。经过长时间的谷歌搜索,我发现我的错误是由多个用户在他们的帐户中添加了相同的密钥引起的。

So, here is my solution: delete the wrong-user's ssh-key (I can do it because the wrong-user is also my account). If the wrong-user isn't your account, you may need to change your ssh-key, but I don't think this gonna happen.

所以,这是我的解决方案:删除错误用户的 ssh-key(我可以这样做,因为错误用户也是我的帐户)。如果错误的用户不是您的帐户,您可能需要更改 ssh 密钥,但我认为这不会发生。

And I think your problem may be caused by a mistyping error in your accounts name.

我认为您的问题可能是由您的帐户名称输入错误引起的。

回答by Bash

This problem is also caused by:

这个问题也是由以下原因引起的:

If you are on a mac/linux, and are using 'ControlMaster' in your ~/.ssh/config, there may be some ssh control master processes running.

如果您使用的是 mac/linux,并且在您的 ~/.ssh/config 中使用“ControlMaster”,则可能有一些 ssh 控制主进程正在运行。

To find them, run:

要找到它们,请运行:

ps aux | grep '\[mux\]'

And kill the relevant ones.

并杀死相关的。