You can have git use a specific 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.
When in the desired repo on your terminal, configure by:
git config core.sshCommand "ssh -i ~/.ssh/id_ecdsa_clientX"
In this case, you’re directly configuring
git doing under the hood? It uses an SSH environment variable to execute commands based on your config.
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 configuration. You do not need to supply the env variable to each git command.
Simple and elegant.
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 find the 2.10.0 release notes here.
Quote for convenience:
A new configuration variable core.sshCommand has been added to specify what value for GIT_SSH_COMMAND to use per repository.