我正在尝试使用自定义 SSH 命令克隆 Git 存储库。我在 GIT_SSH 环境中设置 SSH 命令可变地运行
export GIT_SSH="/usr/bin/ssh -o StrictHostKeyChecking=no -i/home/me/my_private_key"
。
但是当我运行上一个命令后
git clone git@bitbucket.org:uname/test-git-repo.git
,我得到以下奇怪的错误
error: cannot run /usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key
fatal: unable to fork
你能帮我解决这个问题吗?
最佳答案
您不能在 GIT_SSH
环境变量中提供选项;来自 git
手册页:
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.
一个选项是使用适当的配置将节添加到您的 .ssh/config
文件:
Host bitbucket.org
StrictHostKeyChecking no
IdentityFile /home/me/my_private_key
另一种选择是将 GIT_SSH
指向执行您想要的操作的 shell 脚本。例如,在 /home/me/bin/bitbucket_ssh
中,放入:
#!/bin/sh
exec /usr/bin/ssh -o StrictHostKeyChecking=no -i /home/me/my_private_key "$@"
然后将 GIT_SSH
指向 /home/me/bin/bitbucket_ssh
。
如果可能,我更喜欢使用 .ssh/config
,因为这避免了为每个远程创建每个目标脚本的需要。
关于使用 GIT_SSH 错误使用自定义 SSH 进行 Git 克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14220929/