git 如何仅为特定存储库设置 GIT_SSL_NO_VERIFY?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9008309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:50:22  来源:igfitidea点击:

How do I set GIT_SSL_NO_VERIFY for specific repos only?

gitssl

提问by Charles Randall

I have to use a git server without proper certificates, but I don't want to have to do

我必须使用没有适当证书的 git 服务器,但我不想这样做

env GIT_SSL_NO_VERIFY=true git command

every single time I do a git operation. But I would also like to leave SSL enabled for other git repositories. Is there a way to make this local to a single repo?

每次我进行 git 操作时。但我还想为其他 git 存储库启用 SSL。有没有办法将这个本地化为单个回购?

回答by Joachim Isaksson

You can do

你可以做

git config http.sslVerify false

in your specific repo to disable SSL certificate checking for that repo only.

在您的特定存储库中仅禁用该存储库的 SSL 证书检查。

回答by Thirumalai murugan

You can do as follows

您可以执行以下操作

For a single repo

对于单个回购

git config http.sslVerify false

For all repo

对于所有回购

git config --global http.sslVerify false

回答by mcepl

Like what Thirumalai said, but inside of the cloned repository and without --global. I.e.,

就像 Thirumalai 所说的那样,但是在克隆的存储库中并且没有--global. IE,

  1. GIT_SSL_NO_VERIFY=true git clone https://url
  2. cd <directory-of-the-clone>
  3. git config http.sslVerify false
  1. GIT_SSL_NO_VERIFY=true git clone https://url
  2. cd <directory-of-the-clone>
  3. git config http.sslVerify false

回答by user5958256

In particular if you need recursive clone

特别是如果您需要递归克隆

GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/xx/xx.git

回答by shasi kanth

If you are on a Windows machine and have the Git installed, you can try the below steps:

如果您使用的是 Windows 机器并安装了 Git,您可以尝试以下步骤:

  1. Go to the folder of Git installation, ex: C:\Program Files (x86)\Git\etc
  2. Edit the file: gitconfig
  3. Under the [http]section, add the line: sslVerify = false

    [http]
      sslVerify = false
    
  1. 进入 Git 安装文件夹,例如:C:\Program Files (x86)\Git\etc
  2. 编辑文件:gitconfig
  3. [http]部分下,添加以下行:sslVerify = false

    [http]
      sslVerify = false
    

回答by Matthias B

There is an easy way of configuring GIT to handle your server the right way. Just add an specific http section for your git server and specify which certificate (Base64 encoded) to trust:

有一种配置 GIT 以正确方式处理服务器的简单方法。只需为您的 git 服务器添加一个特定的 http 部分并指定要信任的证书(Base64 编码):

~/.gitconfig

~/.gitconfig

[http "https://repo.your-server.com"]
# windows path use double back slashes
#  sslCaInfo = C:\Users\<user>\repo.your-server.com.cer
# unix path to certificate (Base64 encoded)
sslCaInfo = /home/<user>/repo.your-server.com.cer

This way you will have no more SSL errors and validate the (usually) self-signed certificate. This is the best way to go, as it protects you from man-in-the-middle attacks. When you just disable ssl verification you are vulnerable to these kind of attacks.

这样您就不会再有 SSL 错误并验证(通常)自签名证书。这是最好的方法,因为它可以保护您免受中间人攻击。当您仅禁用 ssl 验证时,您很容易受到此类攻击。

https://git-scm.com/docs/git-config#git-config-httplturlgt

https://git-scm.com/docs/git-config#git-config-httplturlgt

回答by Mat M

If you have to disable SSL checks for one git server hosting several repositories, you can run :

如果您必须为托管多个存储库的一台 git 服务器禁用 SSL 检查,您可以运行:

git config --bool --get-urlmatch http.sslverify https://my.bad.server false

(If you still use git < v1.8.5, run git config --global http.https://my.bad.server.sslVerify false)

(如果你仍然使用 git < v1.8.5,运行git config --global http.https://my.bad.server.sslVerify false

Explanation from the documentationwhere the command is at the end, show the .gitconfigcontent looking like:

命令末尾的文档说明,显示 .gitconfig内容如下:

[http "https://my.bad.server"]
        sslVerify = false

It will ignore any certificate checks for this server, whatever the repository.

无论存储库是什么,它都会忽略对该服务器的任何证书检查。

You also have some explanation in the code

你在代码中也有一些解释

回答by Tadej

This works for me:

这对我有用:

git init
git config --global http.sslVerify false
git clone https://myurl/myrepo.git

回答by mrexodia

This question keeps coming up and I did not find a satisfying result yet, so here is what worked for me (based on a previous answer https://stackoverflow.com/a/52706362/1806760, which is not working):

这个问题不断出现,我还没有找到令人满意的结果,所以这对我有用(基于之前的答案https://stackoverflow.com/a/52706362/1806760,它不起作用):

My server is https://gitlab.devwith a self-signed certificate.

我的服务器https://gitlab.dev带有自签名证书。

First run git config --system --edit(from an elevated command prompt, change --systemto --globalif you want to do it for just your user), then insert the following snippet after any previous [http]sections:

首先运行git config --system --edit(从提升的命令提示符,更改--system--global如果您只想为您的用户执行此操作),然后在之前的任何[http]部分之后插入以下代码段:

[http "https://gitlab.dev"]
        sslVerify = false

Then check if you did everything correctly:

然后检查您是否正确执行了所有操作:

> git config --type=bool --get-urlmatch http.sslVerify https://gitlab.dev
false

回答by 176coding

for windows, if you want global config, then run

对于 Windows,如果你想要全局配置,然后运行

git config --global http.sslVerify false