使用 GIT_SSH 错误使用自定义 SSH 进行 Git 克隆

标签 git ssh environment-variables clone git-clone

我正在尝试使用自定义 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/

相关文章:

ssh - 无法使用 Putty 通过 ssh 启动 X11

git - 通过 SSH 推送到远程存储库时为 "Access denied"

gradle - 使用kaniko时无法在build.gradle UPD中访问gitlab-ci环境变量

php - LAMP 环境变量 ($PATH) 出现问题

git - 缺少 git 中提交的更改

android - 为 Android 构建启动器

linux - Nginx 默认配置目录

Git - 将所有提交转移到另一个分支并创建一个新的主分支

c# - 在 C# 中连接到 AWS Managed SFTP 服务器时 SSH.NET 超时

dll - CTest、CMake 和 MinGW : Executables build, 但无法运行,因为找不到新的 DLL