My SSH key was setup for GitHub and working fine, but I wanted to add a separate one for Bitbucket1. It was daunting playing around with this when everything was already working largely as I expected, but it was simple to get this as I wanted.
First, backup your existing keys first in case something goes wrong and you accidentally overwrite them. (You're backing up your data anyway, right?)
Create a new
key. If you've
id_rsa key already, you can name the new key e.g.
~/.ssh/id_rsa.1 (or 2, 3...). (Initially, I put the new key in a
separate Bitbucket directory and I don't think that the
automatically pick it up there, so I moved it back to the
Add the following to
Host github.com User git IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes Host bitbucket.org User git IdentityFile ~/.ssh/id_rsa.1 IdentitiesOnly yes
ensures that only the specified key is used for that host; if you don't
have this, you may end up failing to
as too many incorrect keys have been passed to the server.
If you're using the key in this session, you might need to
In my case, on Ubuntu 12.04, on subsequent logins, the new key was made
Unlike GitHub, Bitbucket only matches commits when the commit contains an email address that has been confirmed on Bitbucket, so any commits you make aren't matched to your user account. You can override this by setting aliases, but this is on a per repository basis and you can't do this unless you're an admin of the repository. ↩