Managing multiple Repository Access keys on one device

If you have a tool or script that requires access to more than one Bitbucket Cloud repositories through SSH, some additional configuration is required to ensure that Git connects to Bitbucket with the correct SSH key for each repository cloned to your device.

To configure your device to access multiple repositories using read-only Repository Access Keys:

  1. Check that SSH is installed (see the relevant SSH setup guide for your operating system).

  2. Create an SSH key pair for each repository in the ~/.ssh/ directory, such as:

    1 2 cd ~/.ssh/ ssh-keygen -t ed25519 -b 4096 -C "{username@emaildomain.com}" -f {ssh-key-name}
  3. Add the public keys to the corresponding repositories on Bitbucket Cloud (see the relevant SSH setup guide for your operating system).

  4. Create or update each repository’s .gitconfig (not the user’s global Git configuration at ~/.gitconfig) to include the core.sshCommand setting, with an ssh command that uses the private key for the repository, such as:
    ~/repository1/.gitconfig

    1 2 [core] sshCommand = ssh -i ~/.ssh/repository1_private_ssh-key-name

    ~/repository2/.gitconfig

    1 2 [core] sshCommand = ssh -i ~/.ssh/repository2_private_ssh-key-name
  5. Update the user’s global Git configuration file ~/.gitconfig to conditionally include the repository Git configuration files using the includeIf setting. For example:

    1 2 3 4 5 [includeIf "gitdir:~/repository1/"] path = ~/repository1/.gitconfig [includeIf "gitdir:~/repository2/"] path = ~/repository2/.gitconfig

Additional Help