I am having trouble getting multiple GitHub accounts working on the 1 machine (Windows 11). Here's the scenario. My work has a Github account. Let's call it jonatwork. I have a personal Github account. Let's call it jonathome.
I already set up ssh for jonathome, with id_rsa
as my ssh key.
These are the steps I took to create a second ssh key etc. for jonatwork.
-1- I created a new ssh key called id_rsa_jonwork
-2- I added that key to the ssh keys on that GitHub account (jonatwork), using the GitHub site. (Basically copied the public key, dumped it in a textbox, named it and clicked add key).
-3- I created a file in ~/.ssh called config, the contents of which are:
#jonwork account
Host jonwork
HostName github.com
AddKeysToAgent yes
User git
IdentityFile ~/.ssh/id_rsa_jonwork
#jonhome account
Host jonhome
HostName github.com
AddKeysToAgent yes
User git
IdentityFile ~/.ssh/id_rsa
With that in place, I created a new repo on the jonatwork GitHub account using the GitHub site. I then cloned that repo, with jonwork:
as a suffix.
I added the name and email to that repo using bash.
When I went to do my first push
, I was prompted for the password for the jonatwork ssh key. This boded well.
But when I looked at the Github interface, the User for that commit was listed as jonathome.
This is the wrong user. So, that repo had 2 users contributing. jonatwork did the first commit (on creation in the interface) and jonathome (wrong user) did the 2nd commit (pushed via bash).
Can anyone see what I have missed to achieve this?
CodePudding user response:
But when I looked at the Github interface, the User for that commit was listed as jonathome.
This has nothing to do with SSH authentication.
You can check the user locally, before any push, with git log --pretty=" %C(reset)