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!
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.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With