'configure multiple git accounts with config file only recognises first GitHub account and ignores second
I'm trying to set up multiple Github.com accounts on my computer. I've followed this tutorial and also this one here. However, I'm having issues. I'm working on the Unbuntu Linux subsystem on windows.
My ssh config file is as follows:
# personal git hub
Host github.com
Hostname github.com
User git
IdentityFile ~/.ssh/id_ecdsa_gh
# work git hub
Host github-work
Hostname github.com
User git
IdentityFile ~/.ssh/id_ecdsa
The issue is that if I specify that the host for my personal (primary) github account as github.com and I push a repo associated with this account then everything works fine for this account. However, the work account no longer works and I get a message in terminal saying Please make sure you have the correct access rights and the repository exists.
If I then change my config file and specify the host for personal account as something like personal then it no longer works but my work account will then begin working fine. If I change both so neither Host is called github.com then my work account can push but my personal one is unrecognised. If I set both to github.com then my personal account works again and my work account does not.
Aside from the above tests with changing the host name, I've also tried deleting and updating the keys, which din't work. I've also tried testing that the ssh keys are recognised by git by using ssh -T myname-git and ssh -T work-git. In doing this I get messages telling me Hi [account name] successfully authenticated, but Github does not provide shell access. So the keys both work fine and are recognised by Github. I'm really not sure what's causing this. I've cleared and re-added the keys with ssh-add and I've checked the repos I'm working with are locally associated with the correct accounts and that there are no commits accidentally associated with the wrong accounts. Further I've check that both the global account on windows and the global account on the Linux subsystem are set to the credentials of my personal account. I've also been through the Q&As on stack looking at similar questions, but none of the suggested methods solved this for me.
Can anyone suggest what could be wrong and how I could fix it?
Thanks for reading.
Solution 1:[1]
The way SSH config files are parsed, the first line/block that matches the hostname is applied, and the rest of the file isn’t processed. The match is done on the Host line; you need to do git clone git://git@github-work/user/repo.git (possibly without the git@) to instruct it to use the second config.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrew H |
