Another option made to specify different keys is git config core.sshCommand
with git 2.10 + (Q3 2016).
This is an alternative to the environment variable described in Boris's answer)
See commit 3c8ede3 (26 Jun 2016) by Nguyễn Thái Ngọc Duy (pclouds
).
(Merged by Junio C Hamano -- gitster
-- in commit dc21164, 19 Jul 2016)
A new configuration variable core.sshCommand
has been added to
specify what value for GIT_SSH_COMMAND to use per repository.
Similar to $GIT_ASKPASS
or $GIT_PROXY_COMMAND
, we also read from
config file first then fall back to $GIT_SSH_COMMAND
.
This is useful for selecting different private keys targetting the
same host (e.g. github)
core.sshCommand:
If this variable is set, git fetch
and git push
will use the specified command instead of ssh
when they need to connect to a remote system.
The command is in the same form as the GIT_SSH_COMMAND
environment variable and is overridden when the environment variable is set.
It means the git clone
can be:
cd /path/to/my/repo
git config core.sshCommand 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
# later on
git clone host:repo.git
If you want to apply that for all repos, as user1300959 adds in the comments, you would use a global configuration.
git config --global core.sshCommand 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'