Have you ever tried to use multiple repositories from the same vendor (GitHub, BitBucket, GitLab, ...) but with different SSH keys? Well, that's not easy.
Indeed, your SSH agent will probably only support automatically one key per domain. However, you can assign specific keys to each repository with adequate git configuration settings (core.sshCommand
).
This repository contains a collection of shell scripts to facilitate git repositories management with multiple SSH keys.
Most scripts will guide you through the process.
In case your agent loses track of some of your keys, you can all them all at once with this script. Keys must be stored in ~/.ssh
(which is the default SSH folder).
Usage:
ssh-add-all-keys.sh
Clones a repository and assigns a SSH key to it. The specified repository will be cloned in a sub-folder.
Usage:
gcssh <git_ssh_uri>
Adds a new remote to an existing repository and assign a specific SSH key to it. You must execute this script from the folder of the repository. Useful if the git repository has been initialized locally and not cloned.
Usage:
garssh <git_remote_ssh_uri>
Adds a submodule to an existing repository and assign a specific SSH to it. You must execute this script for the folder of the repository.
Usage:
gasmssh <git_submodule_ssh_uri>
In some cases, submodules must be initialized with the SSH key of the repository. This script is designed for that. You must execute this script for the folder of the repository.
Usage:
gismssh
This script sets the SSH key to use for a repository. You must execute this script for the folder of the repository.
Usage:
gsetsshcfg