Git克隆与自定义SSH使用GIT_SSH错误 [英] Git clone with custom SSH using GIT_SSH error

查看:501
本文介绍了Git克隆与自定义SSH使用GIT_SSH错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用自定义SSH命令克隆Git repo。我设置的SSH命令在GIT_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 /家/我/ 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

另一个选项是指向$ code> 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使用GIT_SSH错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆