I am trying to clone a Git repo using a custom SSH command. I set the SSH command in the GIT_SSH environmental variably be running
export GIT_SSH="/usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key"
.
But when, after the previous command I run
git clone [email protected]:uname/test-git-repo.git
, I get the following weird error
error: cannot run /usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key fatal: unable to fork
Can you please help me out solve this issue?
GIT_SSH , if specified, is a program that is invoked instead of ssh when Git tries to connect to an SSH host. It is invoked like $GIT_SSH [username@]host [-p <port>] <command> .
Since git just uses ssh to connect, it will use whichever key ssh would use to connect to the remote host. See the ~/. ssh/config file for details; the host block uses the IdentityFile directive to specify the private key to use.
You cannot provide options in the GIT_SSH
environment variable; from the git
man page:
GIT_SSH If this environment variable is set then git fetch and git push will use this command instead of ssh when they need to connect to a remote system. The $GIT_SSH command will be given exactly two arguments: the username@host (or just host) from the URL and the shell command to execute on that remote system. To pass options to the program that you want to list in GIT_SSH you will need to wrap the program and options into a shell script, then set GIT_SSH to refer to the shell script.
One option is to add a stanza to your .ssh/config
file with the appropriate configuration:
Host bitbucket.org StrictHostKeyChecking no IdentityFile /home/me/my_private_key
Another option is to point GIT_SSH
to a shell script that does what you want. E.g., in /home/me/bin/bitbucket_ssh
, put:
#!/bin/sh exec /usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key "$@"
And then point GIT_SSH
at /home/me/bin/bitbucket_ssh
.
I prefer using .ssh/config
when possible, because this avoids the need to create a per-destination script for each remote.
Note that starting with git 2.3+ (Q1 2015), what you initially tried would work, with the new environment variable GIT_SSH_COMMAND
.
See commit 3994276 from Thomas Quinot (quinot
):
git_connect
: set ssh shell command in GIT_SSH_COMMAND
It may be impractical to install a wrapper script for
GIT_SSH
when additional parameters need to be passed.
Provide an alternative way of specifying a shell command to be run, including command line arguments, by means of theGIT_SSH_COMMAND
environment variable, which behaves likeGIT_SSH
but is passed to the shell.The special circuitry to modify parameters in the case of using PuTTY's plink/tortoiseplink is activated only when using
GIT_SSH
; in the case of usingGIT_SSH_COMMAND
, it is deliberately left up to the user to make any required parameters adaptation before calling the underlying ssh implementation.
GIT_SSH_COMMAND
:If either of these environment variables is set then '
git fetch
' and 'git push
' will use the specified command instead of 'ssh
' when they need to connect to a remote system.
The command will be given exactly two or four arguments:
- the '
username@host
' (or just 'host
') from the URL and the shell command to execute on that remote system, optionally preceded by '-p
' (literally) and- the '
port
' from the URL when it specifies something other than the defaultSSH
port.
$GIT_SSH_COMMAND
takes precedence over$GIT_SSH
, and is interpreted by the shell, which allows additional arguments to be included.$GIT_SSH
on the other hand must be just the path to a program (which can be a wrapper shell script, if additional arguments are needed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With