Multiple SSH Bitbucket accounts on the same machine
I am trying to get multiple Bitbucket accounts running from the same machine via SSH.
In my .ssh \ config file I have:
Host account1.bitbucket.org
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/account1
Host account2.bitbucket.org
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/account2
Then I change the remote for the git repository to use an alias:
git@account1.bitbucket.org:myUserName/myRepoName.git git@account2.bitbucket.org:myUserName/myRepoName.git
Then in Pageant (in the system tray) I add both PPKs.
Unfortunately, if I added both keys to "Paint", only one of the accounts works.
If I only have one key in Pageant at a time, then it will work for whatever Bitbucket account is added to Projectant.
So, it looks like the lookup is not using the correct key if there is more than one key in its list.
Any ideas on why he is doing this?
source to share
I got this working without using Pageant. I'm using Sourcetree as my Git GUI, and there is a dropdown in the options about whether to use OpenSSH or Putty / Plink.
Based on Steve Streeting's description here:
https://answers.atlassian.com/questions/164479/sourcetree-support-multiple-ssh-keys
It looks like Paige is not using the .ssh \ config config.
By switching to OpenSSH and then recovering the keys using ssh-keygen and adding the private keys through the Scrcetree menu "Tools .. Add SSH Keys", it now works fine using different keys for multiple accounts. I just need to change the remote url of each Git repository to use the correct alias in the config file (as described in my original post).
Update
I wrote a blog post about this here: http://www.danclarke.com/multiple-ssh-keys-for-git/
source to share
This link on Atlassian Answers explains how to use PuTTY and SSH with multiple bitbucket accounts:
One way to solve this problem is to do the same configuration in PuTTY to eliminate which key to send (and thus which user to authenticate as).
Start PuTTY (download it from putty.org if you don't have it)
Enter "bitbucket.org" in the hostname field
Go to Connection> SSH> Auth in the tree
Specify the key to be used for user BB
Go back to the "Session" section in the tree
Enter an alias under "Saved Sessions" (eg bb-user1) and Save
Repeat 2-6 for each BB user and save as a different session name
Then, in your remote URLs, replace "bitbucket.org" with session (eg bb-user1) to eliminate which SSH key to send first. This is identical to the use of IdentityFile in OpenSSH.
Finally, you can add keys to the pageant to cache key passwords.
source to share