How to manage multiple GitHub accounts using git on Windows and fix git push with wrong user name

Sometimes it happen when we have to use multiple GitHub accounts on a single machine, but it quite tricky to handle in a proper way. Let me describe full steps including some issues I’ve faced and its fixes.

Step 1 – Setup SSH Keys

# lets assume the first user account is:
# and the second one:

# use git bash
# change directory to ~/.ssh/ which located on: %USERPROFILE%\.ssh

$ cd ~/.ssh/
$ ssh-keygen -t rsa -C

# skip passphrases and the output will look like:

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Admin/.ssh/id_rsa): id_rsa_user1
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_user1
Your public key has been saved in
The key fingerprint is:
The key's randomart image is:
+---[RSA 3072]----+
|OBO. +           |
|+O+=B+o  .       |

# same for the second user
$ ssh-keygen -t rsa -C


Enter file in which to save the key (/c/Users/Admin/.ssh/id_rsa): id_rsa_user2

In result four files will be generated in ~/.ssh :




Step 2 – Prepare configuration file

In ~/.ssh/ ( %USERPROFILE%\.ssh ) create a config and enter the keys we’ve just generated:

# github for
Host user1
    User git
    IdentityFile ~/.ssh/id_rsa_user1

# github for
Host user2
    User git
    IdentityFile ~/.ssh/id_rsa_user2


Step 3 – Add newly generated keys to

Go to ➤ Settings ➤ SSH and GPG keys ➤ SSH Keys ➤ New SSH Key:

Enter some title and in the Key field enter the public key content from ~/.ssh/ and ~/.ssh/ to the related GitHub accounts respectively.


Step 4 – Register Identities

# check already existed identities
$ ssh-add -l

# if there is a case & you'd like to delete already existed ones, use the next command:
$ ssh-add -D

# register new ones
$ ssh-add.exe id_rsa_user1
Identity added: id_rsa_user1 (

$ ssh-add.exe id_rsa_user2
Identity added: id_rsa_user2 (

But, if you face the next type error, like:

Could not open a connection to your authentication agent.

Then you’ve to initialize the ssh-agent:

$ exec ssh-agent bash


Step 5 – Verify

To verify configuration we need to test prepared keys by running next commands:

$ ssh -T user1

If you see errors like: ssh: Could not resolve hostname user1 .. or smth else, please check the previous steps.

In case of success you should see the message smth like this:

# Hi <USER1_USERNAME>! You've successfully authenticated, but GitHub does not provide shell access.

The same should appear in case of running: ssh -T user2 command, but be careful, if the

WARNING: If in the second time you’ll see the same username for the user1, it mans that there are some errors, might be the key was not registered to the proper user, so git by default will use the user1 account instead. So be sure that the testing key output will be with the proper username, like:

# Hi <USER2_USERNAME>! You've successfully authenticated, but GitHub does not provide shell access.


Step 6 – Test PUSH Requests

$ git remote add origin git@user1:some-github-access-granted-account/project.git
$ git push origin main
$ git remote add origin git@user2:some-github-access-granted-account/project.git
$ git push origin main

WARNING: Be careful, when submitting with second user, despite that correct user account (in our case user2) is used, author on still could be the user1 ‘s name, in case if both the users have access to the shared project. At least, I faced the problem at the moment there is a very simple solution for it, namely on user2 ‘s copy of repo set local git configuration using next command:

$ git config --local



test user in verbose mode:

$ ssh -T user1

If getting error like: Bad owner or permissions on ~/.ssh/config change permissions:

chmod 600 ~/.ssh/config

Config path on CentOS for regular users:




One thought on “How to manage multiple GitHub accounts using git on Windows and fix git push with wrong user name

Leave a Reply