Github多个帐户-对personalUserName/repoName.git的权限被拒绝给globalUserName [英] Github multiple accounts - Permission to personalUserName/repoName.git denied to globalUserName
问题描述
更新5/14/2018 我更新了操作系统,不得不重新启动计算机,因此这显然使我对这个问题的修复陷入了混乱,这似乎是暂时的.要再次临时解决此问题,我必须执行以下操作:
Update 5/14/2018 I updated my OS and had to reboot my machine, so this apparently messed up my fix to this issue, which seems to have been temporary. To temporarily fix this again, I had to do the following:
- 运行
eval"$(ssh-agent -s)"
-
ssh-add〜/.ssh/your-ssh-key
- 输入ssh密钥密码
- 运行您想要的任何git命令
我需要研究使其永久化.这绝对与我在.ssh/config文件中注释掉 Host *
部分有关,因此,我需要弄清楚如何对部分而非全部主机使用钥匙串,因为所有主机均无法正常工作用于我的设置.
I need to look into making this permanent. It is definitely related to me commenting out the Host *
section from my .ssh/config file, so I need to figure out how to use keychain for some and not all hosts, since all hosts is not working for my setup.
更新5/2/2018:
万一有人遇到此问题,我可以使用 ssh -vT git@github.com
的输出来查找从何处获取配置,这使我不得不做一些事情解决我的问题:
In case anyone has this issue, I used the output of ssh -vT git@github.com
to find where the configuration was being picked up from and this lead me to do a few things to fix my issue:
- 从我的根目录
〜
中找到的 - 如上所示,我在
.ssh/config
文件中有一个针对Host *
的部分,我对此进行了注释 - 确认已针对我正在处理的特定存储库正确设置了
git config user.name
和git config user.email
- 确认我的远程仓库已正确设置,例如
git remote set-url origin git @ github-newkeyname:repo_git_target
.gitconfig
中删除了 name
值- removed
name
value from my.gitconfig
found in my root folder~
- as shown above, I had a section in my
.ssh/config
file forHost *
which I commented out - confirmed that
git config user.name
andgit config user.email
were set correctly for the specific repo I was working on - confirmed my remote repo was set properly, e.g.
git remote set-url origin git@github-newkeyname:repo_git_target
谢谢.
我有一个工作和一个个人GitHub帐户,最近想使用我的个人帐户.但是,我不断收到一条错误消息,说
I have a work and a personal GitHub account and recently wanted to work on my personal account. However, I kept getting an error message saying
对personalUserName/repoName.git的权限被拒绝给globalUserName
I looked up how to work with multiple GitHub accounts and found this tutorial - https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574
我按照所有说明进行操作,最后按照教程中的说明使用新密钥添加了遥控器,例如
I followed all the instructions and finally added the remote using the new key, as described in the tutorial, e.g.
git remote add origin git @ github-newkeyname:username/repoName.git
当我尝试从本地项目推送到个人GitHub存储库时,出现以下错误:
When I try to push from my local project to my personal GitHub repo, I get the following error:
ERROR: Permission to localUserName/repoName.git denied to globalUserName.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我在这里注意到的一件事是, localUserName/repoName.git
包括我添加了 git config user.name
的本地用户名,并且错误显示权限被拒绝(很久以前)使用 git config --global user.name
添加的用户名.
The one thing I notice here is that the localUserName/repoName.git
includes the local username I added with git config user.name
, and the error shows that permission was denied to the username added (a long time ago) with git config --global user.name
.
我不确定问题是否与SSH密钥或git config或两者有关.有人有建议吗?
I am unsure if the issue is related to the SSH keys or to the git config, or both. Does anyone have any suggestions?
当我使用 ssh -vT git @ github-newkeyname
和 ssh -vT git @ github
测试我的SSH连接时,在在这种情况下,我称之为globalUserName,即
When I test my SSH connection with ssh -vT git@github-newkeyname
and ssh -vT git@github
, I see both authenticating with the same username, in this case, that which I call the globalUserName, i.e.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi globalUserName! You've successfully authenticated, but GitHub does not provide shell access.
这是我在相关位置的SSH配置文件的样子:
This is what my SSH config file looks like at the relevant places:
94 Host *
95 UseKeychain yes
96 AddKeysToAgent yes
97 IdentityFile ~/.ssh/someFile.pem
98
99 Host github-newkeyname
100 Hostname github.com
101 User git
102 IdentityFile ~/.ssh/id_rsa_newkeyname
103 IdentitiesOnly yes
推荐答案
我遇到了同样的问题-更改了本地存储库的配置后,提交/推送仍在向我的 old 用户注册,没有回购访问权限(回购是由我的 new 用户身份创建的).
I had the same issue - whereby after changing my local repo's config, commits/pushes were still being registered to my old user, which didn't have repo access (the repo was created by my new user identity).
问题不是我的旧(全局")用户仍被分配给新提交-而是该用户仍与旧提交相关联(在更新我的 ./git/config
之前,并且我的SSH设置不正确.
The issue wasn't that my old ('global') user was still being assigned to new commits - rather, that user was still connected to the old commits (prior to updating my ./git/config
, and my SSH wasn't setup correctly.
我通过以下方法解决了这个问题:
I solved this by:
- (假设已经完成,但是:)设置特定于回购协议的
user
&./git/config
中的 - 确保我的ssh密钥对于此新的github身份处于活动状态,
ssh-add -K〜/.ssh/id_rsa_newkeyname
- 重新启动计算机(可能完全是多余的,但以防万一它很重要)
- 将我的分阶段更改推送到仓库(这些更改与我的
global-user
相关联,因为我在之前更改了我的./git/config
用户设置,但正确添加了我的其他ssh键后,可以继续进行推送 - 完成后,进入阶段&正常提交-所有这些都分配给新的github身份:party:
电子邮件
- (Assuming this is done already, but:) Setting a repo-specific
user
&email
within./git/config
- Making sure my ssh key was active for this new github identity,
ssh-add -K ~/.ssh/id_rsa_newkeyname
- Restarting my computer (probably totally superfluous, but just in case it's important)
- Pushing my staged changes to the repo (these changes were associated to my
global-user
, as I made them before changing my./git/config
user settings, but the correct addition of my other ssh key allowed the push to go ahead - Once done, stage & commit as normal - all of which are being assigned to the new github identity :party:
这篇关于Github多个帐户-对personalUserName/repoName.git的权限被拒绝给globalUserName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!