Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github multiple accounts - Permission to personalUserName/repoName.git denied to globalUserName

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:

  1. ran eval "$(ssh-agent -s)"
  2. ssh-add ~/.ssh/your-ssh-key
  3. enter you ssh key passsphrase
  4. 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 [email protected] to find where the configuration was being picked up from and this lead me to do a few things to fix my issue:

  1. removed name value from my .gitconfig found in my root folder ~
  2. as shown above, I had a section in my .ssh/config file for Host * which I commented out
  3. confirmed that git config user.name and git config user.email were set correctly for the specific repo I was working on
  4. 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
like image 794
thehme Avatar asked Nov 17 '22 17:11

thehme


1 Answers

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).

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:

  1. (Assuming this is done already, but:) Setting a repo-specific user & email within ./git/config
  2. Making sure my ssh key was active for this new github identity, ssh-add -K ~/.ssh/id_rsa_newkeyname
  3. Restarting my computer (probably totally superfluous, but just in case it's important)
  4. 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
  5. Once done, stage & commit as normal - all of which are being assigned to the new github identity :party:
like image 74
RPK Avatar answered Dec 04 '22 07:12

RPK