问题描述
我正在尝试使用自定义 SSH 命令克隆 Git 存储库.我在 GIT_SSH 环境中设置 SSH 命令可变地运行
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 git@bitbucket.org:uname/test-git-repo.git
,我得到以下奇怪的错误
git clone git@bitbucket.org: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
环境变量中提供选项;来自 git
手册页:
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.
一种选择是使用适当的配置将一个节添加到您的 .ssh/config
文件中:
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
另一种选择是将 GIT_SSH
指向执行所需操作的 shell 脚本.例如,在 /home/me/bin/bitbucket_ssh
中,放入:
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 "$@"
然后将 GIT_SSH
指向 /home/me/bin/bitbucket_ssh
.
我更喜欢在可能的情况下使用 .ssh/config
,因为这样可以避免为每个远程创建每个目标的脚本.
I prefer using .ssh/config
when possible, because this avoids the need to create a per-destination script for each remote.
这篇关于使用 GIT_SSH 错误的自定义 SSH 克隆 Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!