Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

push using multiple account / multiple identity on github / bitbucket

I have multiple accounts on github / bitbucket and one unique private-public key pair for each account. The problem occurs when I need to push to the repos created by the different accounts, I will almost certainly get access denied unless I am pushing into the default account (the account that I first created).

Is there a way to switch to different credentials before pushing? I am using Source Tree on Macintosh machine. I'd prefer not to rename ~/.ssh/id_rsa manually whenever I need to push.

Thank you very much for your input!

like image 808
Jenny Kim Avatar asked Sep 10 '13 17:09

Jenny Kim


People also ask

Can I use two different 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.

Can I use same SSH key for different GitHub accounts?

GitHub does not allow us to use the same SSH key in multiple accounts, so we'll have to create separate keys for each account. We can create SSH keys and add them to our SSH agent by following this guide from the GitHub Documentation.

Can I add multiple SSH keys in Bitbucket?

You'll need to create an additional SSH key for each extra Bitbucket account you have or each computer you use. For example, if you have four Bitbucket accounts, you need to generate 3 new SSH keys, meaning you'll have 4 keys in all.


1 Answers

You can use ~/.ssh/config as explained here:

https://confluence.atlassian.com/pages/viewpage.action?pageId=271943168

Host workdid
 HostName bitbucket.org
 IdentityFile ~/.ssh/workdid
Host personalid
 HostName bitbucket.org
 IdentityFile ~/.ssh/personalid

Otherwise, if you just want to "switch account" before doing the pushing, you can use ssh-add. Open the Terminal.app, run ssh-agent and run ssh-add ~/.ssh/path_to_your_account_id_rsa, then do the push. After pushing, you can switch back to your default account by running: ssh-add ~/.ssh/id_rsa.

Hope it helps!

like image 184
Zennichimaro Avatar answered Oct 23 '22 17:10

Zennichimaro