Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub: Multiple account setup

Tags:

github

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.

  1. id_rsa
  2. 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 [email protected]: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.

like image 784
Code Lover Avatar asked Nov 25 '12 16:11

Code Lover


People also ask

Can I have 2 GitHub accounts?

Contributing to two accounts using HTTPS and SSHIf you contribute with two accounts from one workstation, you can access repositories by using a different protocol and credentials for each account. Git can use either the HTTPS or SSH protocol to access and update data in repositories on GitHub.com.

Should I have 2 GitHub accounts?

Should I use separate Github accounts for personal vs professional projects? Yes, always use separate accounts. Things get very messy very quickly otherwise. The company you work for (and most large clients if you freelance/contract) has its own repository, and you will commit to that.


1 Answers

So according to @VonC's answer here what I have done.

  1. I have generate ssh key for another account and added with id_rsa_ac2 (where ac2 is for second account)
  2. Than just cross checked either it works with ssh -T ac2.github.com
  3. Created config file (without extention) in /c/Users/yourname/.ssh/ directory

Here is the code what I used for config file

#Account one
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa
    User git

#Account two
Host ac2.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa_ac2
    User git

So now once you done this you can start to use both account as you need.

for main account I added remote as origin with git remote add origin git@github/youraccount/rep.git Than to push use git push origin master this will upload to your first account.

To add remote for second (ac2) account used git remote add ac2 ac2.github/yoursecondaccount/rep.git Than to push use git push ac2 master this will upload to the second (ac2) account.

To check if it has added remote use git remote -v and incase if you want to remove anyone than use git remote rm origin where origin is your added remote.

Hope this information will helps to other who is having the same issue.

Thanks again to @VonC

like image 139
Code Lover Avatar answered Nov 09 '22 23:11

Code Lover