Sometimes you want to use a specific SSH key when accessing a Git repository, e.g. when using a deploy key.
Use a key for every following git command:
export GIT_SSH_COMMAND="ssh -i /path/to/id_rsa"
Use different keys for different repositories:
In short:
- Add a new entry in
~/.ssh/config
for every repository using a "fake" hostname. - Use the "fake" hostname when cloning.
Example ~/.ssh/config
:
Host github.com-repo-0
Hostname github.com
IdentityFile=/home/user/.ssh/repo-0_deploy_key
Host github.com-repo-1
Hostname github.com
IdentityFile=/home/user/.ssh/repo-1_deploy_key
Example command:
git clone git@github.com-repo-1:OWNER/repo-1.git