Multiple SSH key for git on Bitbucket

If you have more than one Bitbucket repository, then it is not possible to use the same SSH key. This is documented in this thread here.

The workaround is to generate a new SSH key and add it to your second repository.

From here, you must add the SSH key using

ssh-add ~/.ssh/path_to_new_key

Now add the following lines of code to the ~/.ssh/config file:

Host bitbucket.org-newuser
	HostName bitbucket.org
	User git
	IdentityFile ~/.ssh/path_to_new_key

Now the new thing to do is to change the hostname when you check out a repository requiring the use of the new key that you’ve just generated.

For example

git clone git@bitbucket.org:bitbucketuser/a-repo.git

Will become

git clone git@bitbucket.org-newuser:bitbucketuser/a-repo.git

If you have already added a remote origin and wish to change the path then you can use:

git remote set-url origin git@bitbucket.org-newuser:bitbucketuser/a-repo.git