I am trying since more than 3 hours to setting up multiple account for github and litteraly tired. I have tried out almost all possible way describe here, github and articles and none of them worked. I am completely newbie to github and Unix as well. So need your help to fix this. Here below what I am doing
I am using Windows 7 and have set two ssh key for two different accounts.
- id_rsa
- id_rsa_ac2
Than created config file in .ssh directory of the User and added below code
#Account one
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Projects/.ssh/id_rsa
#Account two
Host ac2.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Projects/.ssh/id_rsa_ac2
Now I am trying to add remote by using below code
git remote add origin git@ac2.github.com:myaccount/my.git
and push with bellow code
git push origin master
But when I am trying to push it is giving me Error:
Error: Permission to myaccount/my.git denied to {account}. // where it is considering default user account and not for ac2 user account
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Thanks a lot..
Additional Info:
I have test the id_rsa_ac2 and giving successfully authenticated message. But the strange thing is giving username with original account not with the ac2 account username
Hi {username!} You've successfully authenticated, but GitHub does not provide shell access. //here user id should be from ac2 but it is showing userid from id_rsa and not from id_rsa_ac2
INFORMATION: Final Code
@VonC’s answer worked and adding final code as my answer if anyone want to use.
For your config to be taken into account, you need to use its
Hostname in your remote address:If you have defined a
HOMEenvironment variable (which isn’t defined by default on Windows, but is defined if you are using the msysgitgit-cmd.bat) to a directory under which you have your .ssh directory, with itsid_rsa_ac2private key, andid_rsa_ac2.pubpublic key, then it will work.