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?
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.