GitHub and multiple accounts


Hi there!

I have followed this post and having a trouble with my default account getting the following error message. Also, I have checked my both accounts SSH keys were added and named correctly as mentioned in the post. But still getting it.

Thoughts? what I’m doing wrong? Any help would be greatly appreciated.

Thanks in advance. :slight_smile:


The user you’re pushing from is abdurrehman-net but you’re pushing to a repo owned by Abd-Ur-Rehman.
Is that what you’re trying to do? You’ll need to add the former to the repository as a collaborator through GitHub.


I’m trying to push it to user Abd-Ur-Rehman as the user the same user as owner Abd-Ur-Rehman My other user abdurrehman-net works. fine.


You must’ve cloned the repo using the wrong account then. In the future, when cloning a repo, you can specify the user like below, otherwise it uses the global default user.

git clone

For now, you can remove the remote origin and replace it with the correct one, for instance:

git remote set-url origin

You can also check the current remotes using the following command to verify that it worked.

git remote -v


I have added that correctly, I’m trying to push it here and here’s the remote path.


I have two accounts so for other GitHub account which is git@github-abdurrehman-net all is working fine with the SSH key, when I push to my 2nd account git@github-abdurrehman-net everything works fine as it should. But when I push to Abd-Ur-Rehman I get that error. Here’s the config file that I have in my ~/.ssh folder.

#Default GitHub
  User git
  IdentityFile ~/.ssh/id_rsa

Host github-abdurrehman-net
  User git
  IdentityFile ~/.ssh/id_rsa_abdurrehman_net

BTW, on my account abdurrehman-net I’m able to push changes as Abd-Ur-Rehman but I can’t do it for this account it self and when adding the remote origin path it works with both URLs for the abdurrehman-net account.

For example when I add the URL as:


Not sure what I’m doing wrong. :confused:


Sounds to me like both and git@github-abdurrehman-net are pointing to the same “abdurrehman” user. You need one of them to be pointing to “Abd-Ur-Rehman” in order to push changes to their repositories if you don’t want to use collaborator privileges.

You can generate a new key and add it to the Abd-Ur-Rehman account, and set it in the ~/.ssh/id_rsa file (always safe to make a copy of the existing file first).


GitHub provides a test facility for ssh-based connections:

$ ssh -Tv git@github-abdurrehman-net
Hi $USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

I setup a single user with the config you’ve described above and was able to test the ssh config, clone, and push.


I have done this and still getting that same error even though in both accounts separate key is added. I’m stuck with this trying to figured out since Friday and got no luck. :disappointed:


I see now both are appoint to the same user.

How can I make the for the user Abd-Ur-Rehman?


Anybody here?



GitHub uses SSH keys to authenticate you, so you can create a new SSH key and attach it to your “Abd-Ur-Rehman” account on GitHub, save the key in one of your identity files, and update the SSH configuration so that one of your hosts uses that key.

The original tutorial you were following has all the instructions:

  • Create a new SSH key
  • Attach the key to your GitHub account (Abd-Ur-Rehman)
  • Save the key to a new identity file (using ssh-add)
  • Open the ~/.ssh/config file in your editor
  • Edit the "" host and set the correct identity file from step #2


I have followed this and did start over agian but the key I add 1st into SSH agent only works for me the 2nd one doesn’t work. Is there anyway I can mae these working at the same time? When I test the connection see below:


You’re absolutely certain that the host is using the SSH key for the Abd-Ur-Rehman account?

  • Did you overwrite ~/.ssh/id_rsa, or did you add the key to a different file (step 3 above)?
  • Did you make sure that the IdentityFile for is pointing to the correct key file?
  • Can you copy and paste your current ~/.ssh/config file?


Thank you so much for your time and reply.

Yeah, I do. I’ve added them separately. I have figured one thing, instead of having each account as a separate host in the config Now my settings are as below:

Host github
    User git
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/id_rsa_abdurrehman-net
    CheckHostIP no
    ForwardAgent yes
    IdentitiesOnly yes

Now the issue is, the key I add 1st into ssh-agent that only works 2nd one doesn’t.

The key I have above only worked, the 2nd one gives that error. You can see only one work which is above in the following screenshot.

Not sure how to make these work at the same time. :frowning:


Many thanks.


No problem! :smiley:

Okay, so they merged somehow. It’s fine, we can fix this easily!

I’m going to assume that:

  • ~/.ssh/id_rsa is the private key attached to Abd-Ur-Rehman
  • ~/.ssh/id_rsa_abdurrehman-net is the private key attached to abdurrehman-net

If that’s true, then this configuration should work:

# ~/.ssh/config

    User git
    IdentityFile ~/.ssh/id_rsa
    CheckHostIP no
    ForwardAgent yes
    IdentitiesOnly yes

Host github-abdurrehman-net
    User git
    IdentityFile ~/.ssh/id_rsa_abdurrehman-net
    CheckHostIP no
    ForwardAgent yes
    IdentitiesOnly yes

And after you save that, with those two identity files pointing to the different accounts, you should be able to see the different usernames showing up:

ssh -Tv
# Hi Abd-Ur-Rehman!

ssh -Tv git@github-abdurrehman-net
# Hi abdurrehman-net!


Yes, that’s true. I just changed the config file with the text you’ve added above.

I do get the success message see here

After that, I tried to push I got the same error then. As per this video from the post I change the origin path with the hostname as git@abdurrehman-net:abdurrehman-net/travel-site.git it says that couldn’t resolve after that I revert back to the same host then it give same error. See below:


That’s great! Now we’re making progress. :smiley:

With regards to your command:


I believe that it should be github-abdurrehman-net correct? You missed the “github-” portion. Can you give that a try?



OMG! I can’t believe this how did I miss that. It worked! :tada:

Thanks a lot for your time.


No worries mate, glad we could get it working! Don’t hesitate to post on the forums again if you need help with any other tutorials, we’re all here to help. :slight_smile:



Thank you! :+1:

P.S. From now I’ll never ever forget this. :laughing: