Git with multiple accounts gives same username while doing ssh

I have 2 git accounts on my mac for which I have 2 sets of public and private keys.
I have a config file in /.ssh to manage those accounts, which looks like this:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa

Host github-user2
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_user2

Code from these accounts are to be pushed to 2 different remote repositories for which I set their different remotes in their respective directories using following command:

git remote add origin github.com:xyz_user/abc.git
git remote add origin github-user2:pqr_user/def.git

I am successfully able to push to these repos from both accounts.

When I use ssh,

ssh-add -l

shows private keys for both of the accounts added.
But

ssh -T github.com
ssh -T github-user2

both gives the following message:

"Hi user2! You've successfully authenticated, but GitHub does not provide shell access."

1 more thing that I have noticed, even If there is no key listed with ” ssh-add -l”

ssh -T github.com & ssh -T github-user2 provide successful authenticate message.

How will I differentiate between both the accounts while making ssh connection?
Where does ssh -T authenticate from?

  • integrating Jenkins with git
  • can't push to github repo after replasing to another PC
  • Git enter long passphrase for every push
  • cap deploy suddenly says Authentication Failed
  • error when cloning git repository with ssh
  • Give Read-only access to a git repository
  • Gitosis not accepting numbers in hostname
  • system(“git push 2>&1”) works fine, but %x(git push 2>&1) hangs. Why?
  • One Solution collect form web for “Git with multiple accounts gives same username while doing ssh”

    How will I differentiate between both the accounts while making ssh connection?

    You won’t really: both public keys have been registered in the same GitHub account, so as far as GitHub is concerned, both ssh authenticate you as ‘user2’.

    Where does ssh -T authenticate from?

    It is looking in the ssh keys section of your Account profile.
    Both public keys are registered there, as explained in the GitHub help page on “Generating SSH Keys”.

    Git Baby is a git and github fan, let's start git clone.