How to setup multiple ssh keys for multiple bitbucket accounts (Mac OS)

How to setup multiple ssh keys for multiple bitbucket accounts (Mac OS)

  1. Generate 2 ssh keys with the command - ssh-keygen -t rsa. In my case, I generated two files with the names id_rsa and id_rsa_art.
  2. Copy and paste your public keys to bitbucket - https://bitbucket.org/account/settings/ssh-keys/.
  3. cat ~/.ssh/id_rsa.pub | pbcopy
  4. cat ~/.ssh/id_rsa_art.pub | pbcopy
  5. Now, let's config our switching logic. Go to ~/.ssh folder and create their file config with the command - touch config
  6. Open the config file in any text editor and put the instructions below
Host main-bucket
  HostName bitbucket.org
  IdentityFile ~/.ssh/id_rsa 

Host art-bucket
  HostName bitbucket.org
  IdentityFile ~/.ssh/id_rsa_art

We've created 2 configs for bitbucket.org with aliases main-bucket and art-bucket.

  1. Now we can clone our project by replacing bitbucket.org with the respective alias. For example:
  2. git clone git@bitbucket.org:ken2ki/art_project.git -> git clone git@main-bucket:ken2ki/art_project.git
  3. If you already cloned your project, just set the URL with the respective alias as the origin:
  4. git remote add origin git@main-bucket:ken2ki/art_project.git - this would add to list of URLs
  5. git remote set-url origin git@main-bucket:ken2ki/art_project.git - this would set as origin URL
  6. Test it with any git push/pull/fetch/merge/rebase commands


To view or add a comment, sign in

Others also viewed

Explore topics