Search This Blog

14 August 2012

Multiple Accounts/SSH keys on BitBucket

Theoretically, I can add my SSH key to any server I have access to.  With BitBucket, that's not always true.

BitBucket does not allow the same key to be used for two different accounts.  Security measure, I'm sure.  It does make it difficult to access my company account and my personal account from the same machine.

The workaround is to do the initial download via https, then change the protocol.  More specifically....


Assuming 'WORK' and 'HOME' are two separate BitBucket accounts and you are using a single client (laptop, whatever) to access them both...  Decide which one should be less effort -- in this case, I chose WORK.

1. Create an SSH key for WORK
Choose the default /home/username/.ssh/id_rsa
2. Copy into your BitBucket WORK account
3. Create an SSH key for HOME
Choose /home/username/.ssh/id_personal_rsa or something else obvious
4. Copy into your BitBucket HOME account

The Good:

For WORK repos, you can simply do the normal
hg clone ssh://

The Ok, I Guess:

For HOME repos, you have to take an extra step.
hg clone

Then, edit REPO/.hg/hgrc
default = hg clone
default = hg clone ssh://

Then, add this into that file:
ssh = ssh -C -i ~/.ssh/ -o IdentitiesOnly=yes

Now you should be able to push/pull using SSH.


You are probably asking yourself why all of this is necessary.  From scavenging the web and looking at all the "Won't Fix" answers...  My best understanding is because the ssh url BitBucket gives out does not include the username.