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:
Check that SSH is installed (see the relevant SSH setup guide for your operating system).
Create an SSH key pair for each repository in the
~/.ssh/
directory, such as:cd ~/.ssh/ ssh-keygen -t ed25519 -b 4096 -C "{username@emaildomain.com}" -f {ssh-key-name}
Add the public keys to the corresponding repositories on Bitbucket Cloud (see the relevant SSH setup guide for your operating system).
Create or update each repository’s
.gitconfig
(not the user’s global Git configuration at~/.gitconfig
) to include thecore.sshCommand
setting, with anssh
command that uses the private key for the repository, such as:~/repository1/.gitconfig
[core] sshCommand = ssh -i ~/.ssh/repository1_private_ssh-key-name
~/repository2/.gitconfig
[core] sshCommand = ssh -i ~/.ssh/repository2_private_ssh-key-name
Update the user’s global Git configuration file
~/.gitconfig
to conditionally include the repository Git configuration files using theincludeIf
setting. For example:[includeIf "gitdir:~/repository1/"] path = ~/repository1/.gitconfig [includeIf "gitdir:~/repository2/"] path = ~/repository2/.gitconfig
Was this helpful?