git Github 远程权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47465644/
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
Github remote permission denied
提问by Sam Rao
I'm trying to upload my repo on github and go through all the steps upto:
我正在尝试将我的 repo 上传到 github 并完成所有步骤:
git push -u origin master
git push -u origin master
at that point it gives me the following error:
那时它给了我以下错误:
remote: Permission to samrao2/manager-4.git denied to samrao1.
fatal: unable to access 'https://github.com/samrao2/manager-4.git/': The requested URL returned error: 403
远程:samrao2/manager-4.git 的权限被 samrao1 拒绝。
致命:无法访问“ https://github.com/samrao2/manager-4.git/”:请求的 URL 返回错误:403
I think the issue is that i was logged into another Git account before "samrao1" and now i am trying to push to "samrao2".
我认为问题是我在“samrao1”之前登录了另一个 Git 帐户,现在我试图推送到“samrao2”。
Can someone help me reset this to where i can successfully push to "samrao2". I am assuming i will be prompted for my password the first time i try to do it.
有人可以帮我将其重置为可以成功推送到“samrao2”的地方。我假设我第一次尝试时会提示我输入密码。
回答by VonC
Unable to access https means: this has nothing to do with SSH (and switching to SSH, while possible, does not explain the original issue)
无法访问 https 意味着:这与 SSH 无关(并且切换到 SSH,虽然可能,但并不能解释原始问题)
This has to do with credential caching, meaning Git will be default provide the credentials (GitHub account and password) of the old account while you are trying to push to the new account.
这与凭据缓存有关,这意味着当您尝试推送到新帐户时,Git 将默认提供旧帐户的凭据(GitHub 帐户和密码)。
See if you have a credential helperthat would have cached your (old account) credentials (username/password) used to authentication you.
看看您是否有一个凭证助手来缓存您用于验证您的(旧帐户)凭证(用户名/密码)。
git config credential.helper
On Mac, as commentedby Arpit J, just goto/open your keychain access->search for github.com related file->and edit credentials there.
在 Mac 上,正如Arpit J所评论的那样,只需转到/打开您的钥匙串访问-> 搜索 github.com 相关文件-> 并在那里编辑凭据。
See "Updating credentials from the OSX Keychain"
请参阅“从 OSX 钥匙串更新凭据”
On Windows for example, that would be the Windows Credential Managers.
Open the Windows Credential Store, and see if the first user is registered there: delete that entry, and you will be able to authenticate with the second user.
例如,在 Windows 上,这将是Windows Credential Managers。
打开 Windows Credential Store,查看第一个用户是否在那里注册:删除该条目,您将能够向第二个用户进行身份验证。
(Here is an example for BitBucket)
(这里是 BitBucket 的一个例子)
In command-line (see git credential
):
在命令行中(请参阅git credential
):
git credential reject protocol=https host=github.com <empty line here>
and then to set the new username & password:
git credential fill protocol=https host=github.com <empty line here>
git credential reject protocol=https host=github.com <empty line here>
然后设置新的用户名和密码:
git credential fill protocol=https host=github.com <empty line here>
回答by Clinton
I'm not sure what the issue is, but since you mentioned not knowing what having the "right keys installed" means, I'm going to assume you have not set up your computer to authenticate to your Github repository via SSH.
我不确定问题是什么,但由于您提到不知道“安装正确的密钥”意味着什么,我假设您尚未设置您的计算机以通过 SSH 对您的 Github 存储库进行身份验证。
This guide should show you how to do that: Adding a new SSH key to your Github account
本指南应向您展示如何执行此操作: 向您的 Github 帐户添加新的 SSH 密钥
Also, I would suggesting using 'git://github.com/samrao2/manager-4.git/' for your remote URL rather than 'https://github.com/samrao2/manager-4.git/'. The latter requires you to enter a password each time, whereas the former will authenticate via SSH, which is far less irritating. You can change the remote URL in your repository to use the git protocol, instead of https, by typing:
另外,我建议对远程 URL 使用“git://github.com/samrao2/manager-4.git/”,而不是“ https://github.com/samrao2/manager-4.git/”。后者要求您每次都输入密码,而前者将通过 SSH 进行身份验证,这远没有那么刺激。您可以通过键入以下内容来更改存储库中的远程 URL 以使用 git 协议,而不是 https:
git remote set-url origin git://github.com/samrao2/manager-4.git
from within your project directory.
从您的项目目录中。
回答by Novus
If you are using MacOS, you can
如果您使用的是 MacOS,您可以
- go to KeyChain Access,
- Search for "GitHub",
- then when then result "github.com" pops up, change the account or password to your new account, and save.
- 转到钥匙串访问,
- 搜索“GitHub”,
- 然后当结果“github.com”弹出时,将帐户或密码更改为您的新帐户,并保存。
Then you are all set!
那么你就准备好了!
回答by u5819157
Multiple users generate their own ssh key, Generating a new SSH key and adding it to the ssh-agent
AliceRepository, git bash:
git config user.name "Alice"
git config user.email "[email protected]"
eval $(ssh-agent -s)
,ssh-add ~/.ssh/alice.private
ssh -T [email protected]
, Testing your SSH connection- Git other operations
BobRepository, git bash:
git config user.name "Bob"
git config user.email "[email protected]"
eval $(ssh-agent -s)
,ssh-add ~/.ssh/bob.private
ssh -T [email protected]
, Testing your SSH connection- Git other operations
多个用户生成自己的 ssh 密钥,生成新的 SSH 密钥并将其添加到 ssh-agent
爱丽丝存储库,git bash:
git config user.name "Alice"
git config user.email "[email protected]"
eval $(ssh-agent -s)
,ssh-add ~/.ssh/alice.private
ssh -T [email protected]
, 测试您的 SSH 连接- Git其他操作
鲍勃存储库,git bash:
git config user.name "Bob"
git config user.email "[email protected]"
eval $(ssh-agent -s)
,ssh-add ~/.ssh/bob.private
ssh -T [email protected]
, 测试您的 SSH 连接- Git其他操作
回答by Panyam Praneeth Reddy
The problem is you are trying to push into new github account using old github account's ssh key, so generate a new SSH key for the new github account using this link https://help.github.com/en/github/authenticating-to-github/error-permission-to-userrepo-denied-to-userother-repoand then add it your github account. After this try to push, it works
问题是您正在尝试使用旧 github 帐户的 ssh 密钥推送到新的 github 帐户,因此使用此链接为新的 github 帐户生成新的 SSH 密钥https://help.github.com/en/github/authenticating-to -github/error-permission-to-userrepo-denied-to-userother-repo然后将其添加到您的 github 帐户。在尝试推动之后,它起作用了