在Git中使用GIT_SSH_COMMAND for Windows [英] Using GIT_SSH_COMMAND in Git for Windows

查看:258
本文介绍了在Git中使用GIT_SSH_COMMAND for Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用适用于Windows 2.x的第四版Git候选版本,并在shell中使用GIT_SSH_COMMAND以避免SSH的主机验证。
在Git Bash中,我写了这样的内容:

  $ GIT_SSH_COMMAND =ssh -o UserKnownHostsFile = / dev / null -o StrictHostKeyChecking = nogit push origin master 

如何在Windows cmd中执行此类操作?在任何地方都找不到答案。

解决方案

您不必在Windows中设置环境变量。



使用git 2.10+(Q3 2016),您还可以为 GIT_SSH_COMMAND config c>,这比环境变量更容易(可以全局设置,或者本地设置为特定的回购)



请参阅 commit 3c8ede3 (2016年6月26日)作者:NguyễnTháiNgọcDuy( pclouds

(由 Junio C Hamano - gitster - commit dc21164 ,2016年7月19日)


一个新的配置变量 core.sshCommand 已被添加到
指定GIT_SSH_COMMAND为每个存储库使用的值。


< blockquote>

  core.ssh命令:




如果设置了这个变量, git fetch git push 会当它们需要连接到远程系统时,请使用指定的命令而不是 ssh
该命令的格式与 GIT_SSH_COMMAND 环境变量,并且在设置环境变量时被覆盖。


它表示 git push 可以是:

  cd / path / to / my / repo 
git config core.sshCommand'ssh -o UserKnownHostsFile = / dev / null -o StrictHostKeyChecking = no'
#稍后在
git push origin master






使用Git 2.16(Q1 2018),您将有一种新机制来升级线缆建议使用协议,并证明它可以与旧版本的Git协同工作,而不会损害它们。



请参阅 commit 6464679 (2017年10月16日)和 commit 0cd8328 (2017年9月26日)作者: Jonathan Tan( jhowtan

请参阅 commit 94b8ae5 commit 3c88ebd commit 19113a2 commit 0c2f0d2 commit 2609043 commit aa9bab2 commit dfe422d commit 373d70e 提交5d2124b (2017年10月16日) Brandon Williams( mbrandonw

(由 Junio C Hamano - gitster - in commit 4c6dad0 ,2017年12月6日)


ssh :介绍'简单'ssh变体



使用' ssh '运输时,' -o '选项用于指定应在远程端设置的
环境变量。

这允许Git在联系服务器时发送附加信息,
请求使用不同的协议版本通过
' GIT_PROTOCOL '环境变量,如下所示: -o SendEnv = GIT_PROTOCOL 。 / p>

不幸的是,并非所有的ssh变体都支持将环境
变量发送到远程端。

为了解决这个问题,只能使用' -o '选项用于符合OpenSSH的ssh变体。

这是通过检查ba ssh命令的sename是' ssh ',或者ssh变体被重载为' ssh '(通过 ssh.variant config)。



其他选项,如' -p '和' -P ',它们用于指定要使用的特定
端口,或' -4 '和' -6 ',用于表示应该使用IPV4或
IPV6地址,也可能不支持所有ssh
变体。



目前,如果ssh命令的基本名称不是' plink '或
' tortoiseplink ',Git假定该命令是OpenSSH变体。

由于用户配置的ssh命令可能不符合OpenSSH标准,请拧紧$ b $如果
命令的基名与Git已知的变体不匹配,则假设这个约束并假定'简单'的变体。

新的ssh变体' simple '将仅包含主机并执行命令( [username @] host 命令)作为参数传递给 ssh 命令。



I'm using Fourth release candidate of Git for Windows 2.x now, and using GIT_SSH_COMMAND in shell to avoid SSH's host verification. In Git Bash I write something like this:

$ GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git push origin master

How can I do something like this in Windows cmd? Can't find any answers anywhere.

解决方案

You don't have to set an environment variable anymore in Windows.

With git 2.10+ (Q3 2016), you also have the possibility to set a config for GIT_SSH_COMMAND, which is easier than an environment variable (and can be set globally, or locally for a specific repo)

See commit 3c8ede3 (26 Jun 2016) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit dc21164, 19 Jul 2016)

A new configuration variable core.sshCommand has been added to specify what value for GIT_SSH_COMMAND to use per repository.

core.sshCommand:

If this variable is set, git fetch and git push will use the specified command instead of ssh when they need to connect to a remote system.
The command is in the same form as the GIT_SSH_COMMAND environment variable and is overridden when the environment variable is set.

It means the git push can be:

cd /path/to/my/repo
git config core.sshCommand 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' 
# later on
git push origin master


With Git 2.16 (Q1 2018), you will have a new mechanism to upgrade the wire protocol in place is proposed and demonstrated that it works with the older versions of Git without harming them.

See commit 6464679 (16 Oct 2017), and commit 0cd8328 (26 Sep 2017) by Jonathan Tan (jhowtan).
See commit 94b8ae5, commit 3c88ebd, commit 19113a2, commit 0c2f0d2, commit 2609043, commit aa9bab2, commit dfe422d, commit 373d70e, commit 5d2124b (16 Oct 2017) by Brandon Williams (mbrandonw).
(Merged by Junio C Hamano -- gitster -- in commit 4c6dad0, 06 Dec 2017)

ssh: introduce a 'simple' ssh variant

When using the 'ssh' transport, the '-o' option is used to specify an environment variable which should be set on the remote end.
This allows Git to send additional information when contacting the server, requesting the use of a different protocol version via the 'GIT_PROTOCOL' environment variable like so: "-o SendEnv=GIT_PROTOCOL".

Unfortunately not all ssh variants support the sending of environment variables to the remote end.
To account for this, only use the '-o' option for ssh variants which are OpenSSH compliant.
This is done by checking that the basename of the ssh command is 'ssh' or the ssh variant is overridden to be 'ssh' (via the ssh.variant config).

Other options like '-p' and '-P', which are used to specify a specific port to use, or '-4' and '-6', which are used to indicate that IPV4 or IPV6 addresses should be used, may also not be supported by all ssh variants.

Currently if an ssh command's basename wasn't 'plink' or 'tortoiseplink', Git assumes that the command is an OpenSSH variant.
Since user configured ssh commands may not be OpenSSH compliant, tighten this constraint and assume a variant of 'simple' if the basename of the command doesn't match the variants known to Git.
The new ssh variant 'simple' will only have the host and command to execute ([username@]host command) passed as parameters to the ssh command.

这篇关于在Git中使用GIT_SSH_COMMAND for Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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