Skip to main content
Published on

Multiple Bitbucket accounts with SSH on a single machine

A complete guide to setting up and using several Bitbucket accounts (personal and work) on the same workstation with separate SSH keys.

Why set up several Bitbucket accounts?

Managing several Bitbucket accounts (personal and work) on the same machine calls for a specific setup, in order to:

  • Separate work and personal access
  • Keep the different accounts secure
  • Avoid authentication conflicts
  • Maintain clear traceability of contributions

Prerequisites

Before you start, make sure you have:

  • Git installed on your machine
  • A terminal with SSH access
  • Your Bitbucket credentials for each account
  • Administrator rights on your machine

Step-by-step setup

1. Creating the SSH keys

For each Bitbucket account, create a unique SSH key pair:

ssh-keygen -t ed25519 -b 4096 -C "your.email@example.com" -f ~/.ssh/bitbucket-account1
ssh-keygen -t ed25519 -b 4096 -C "work.email@company.com" -f ~/.ssh/bitbucket-account2

Security note: use a strong passphrase for each key.

2. Adding the keys to the SSH agent

Start the SSH agent and configure it:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/bitbucket-account1
ssh-add ~/.ssh/bitbucket-account2

3. SSH configuration

Edit or create the ~/.ssh/config file:

# Personal account
Host bitbucket.org-personal
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/bitbucket-account1
    IdentitiesOnly yes

# Work account
Host bitbucket.org-work
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/bitbucket-account2
    IdentitiesOnly yes

4. Adding the public keys to Bitbucket

  1. Log in to Bitbucket
  2. Go to SSH keys
  3. Add the matching public key to each account:
    cat ~/.ssh/bitbucket-account1.pub
    cat ~/.ssh/bitbucket-account2.pub

Day-to-day use

Cloning a new repository

Use the host alias that matches the account:

# For the personal account
git clone git@bitbucket.org-personal:workspace/repo.git

# For the work account
git clone git@bitbucket.org-work:workspace/repo.git

Updating an existing repository

For repositories that are already cloned, update the remote URL:

git remote set-url origin git@bitbucket.org-personal:workspace/repo.git

Per-repository Git configuration

In each repository, set the appropriate Git identity:

# Configuration local to the repository
git config user.name "Your Name"
git config user.email "matching.email@example.com"

Checking the configuration

Test the connection for each account:

ssh -T git@bitbucket.org-personal
ssh -T git@bitbucket.org-work

Troubleshooting

Common problems

  1. Permission error: check the permissions on the SSH files

    chmod 600 ~/.ssh/bitbucket-*
    chmod 700 ~/.ssh
  2. Key not recognised: check that the SSH agent has actually loaded the key

    ssh-add -l

Additional resources

This setup lets you work efficiently with several Bitbucket accounts on the same machine, while keeping a clear separation between your different usage contexts.

Go further