问题
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:
- ran
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/your-ssh-key
- enter you ssh key passsphrase
- run any git command you want
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.
Update 5/2/2018:
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:
- 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
Thanks.
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
Permission to personalUserName/repoName.git denied to 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
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.
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
.
I am unsure if the issue is related to the SSH keys or to the git config, or both. Does anyone have any suggestions?
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.
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
来源:https://stackoverflow.com/questions/49335136/github-multiple-accounts-permission-to-personalusername-reponame-git-denied-to