Building on larsk's answer and VonC's answer, you can create a git_ssh.sh
script such as:
#!/bin/sh
# Workaround: GIT_SSH_COMMAND isn't supported by Git < 2.3
exec ${GIT_SSH_COMMAND:-ssh} "$@"
Then invoke your git
command like this:
export GIT_SSH_COMMAND="/usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key"
export GIT_SSH=path/to/git_ssh.sh
git ...
This is how it works:
In Git v2.3+ $GIT_SSH_COMMAND
takes precedence over $GIT_SSH
, but older versions don't respect $GIT_SSH_COMMAND
at all.
$GIT_SSH
can hold only a path to the ssh
command on the system. It can't pass extra command line arguments to that command, so how can we pass extra arguments to ssh
?
A workaround is to create a script that includes the ssh
command and its extra arguments. This is exactly what the git_ssh.sh
is all about: Since we already set $GIT_SSH_COMMAND
to be /usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key
, it is exactly what we need to exec
, and the "$@"
is here to pass the arguments passed to git_ssh.sh
by Git itself to the $GIT_SSH_COMMAND.
The ${...:-ssh}
part, while not strictly needed is a nice touch that will make $GIT_SSH_COMMAND
default to the ssh
command, and thus setting GIT_SSH=git_ssh.sh
will not break a normal git
execution.
As added value, this script is totally ignored by Git v2.3+, and the $GIT_SSH_COMMAND
is used directly in this case.
/usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key
in your prompt? – LacroixGIT_SSH_COMMAND
). See my answer below – Falstaffian