You can have git use a speciﬁc SSH key, per repo.
This is great if you have - or would like to use - different SSH keys for each clients. To limit exposure, I try and use separate GitHub/GitLab/BitBucket account + SSH key for each client.
If one key is compromised, none of your other work is exposed.
Show me the code
When in the desired repo on your terminal, conﬁgure by:
git config core.sshCommand "ssh -i ~/.ssh/id_ecdsa_clientX"
In this case, you’re directly conﬁguring
git doing under the hood? It uses an SSH environment variable to execute commands based on your conﬁg.
The abstraction is great because:
- You don’t need to mess with the environment variables on your shell.
- It is a set-it-and-forget-it conﬁguration. You do not need to supply the env variable to each git command.
Simple and elegant.
Introduced in git 2.10
Please note this works on git 2.10 + –- released in late 2016.
You should be covered, but if you wish to check your currently installed version of git, run:
You can ﬁnd the 2.10.0 release notes here.
Quote for convenience:
A new conﬁguration variable core.sshCommand has been added to specify what value for GIT_SSH_COMMAND to use per repository.