Create a unique SSH keypair for each of your accounts and upload the various keys to each of those accounts via the Bitbucket account settings.
Create a file called "config" in the root of your .ssh directory.
In the config file, create a listing for each account you need to manage:
Since these keys have unique names (unlike the default "id_rsa" name) these keys will not be loaded into SSH unless you explicitly request it. You don't want to have to do this every time you open a terminal.
- Open your bash config file. It is probably called ".bashrc" and may exist in the same directory as your ".ssh" directory.
Add the following script, adjusting the private key names to reflect the same names you used above:
eval `ssh-agent -s`
Now whenever you open the terminal you should be prompted for the passwords for each key you added. Once you put in those passwords, you should be all set to push to/pull from any repo connected to those bitbucket accounts.
- But there is one last thing you have to remember. Normally you might add the bitbucket remote repo like this:
git remote add origin email@example.com:myusername/my_project.git
To make use of your config file you need to add those remotes like this;
git remote add origin ssh://firstname.lastname@example.org:myusername/MyUserName/my_project.git
Notice the "ssh://" prepended to the URL. Also notice the addition of "MyUserName" as a sort of subdirectory. When communicating over SSH, that subdirectory path is used by bitbucket to acknowledge you as that user and then your SSH config will serve up the key associated with that user.