我在Windows上使用Git。我安装了msysGit包。我的测试存储库在服务器上有一个自签名证书。我可以毫无问题地使用HTTP访问和使用存储库。移动到HTTPS会出现以下错误:

SSL证书问题:无法获得本地颁发者证书。

我在Windows 7客户端机器的受信任根证书颁发机构中安装了自签名证书。我可以在Internet Explorer中浏览到HTTPS存储库URL,而不会出现错误消息。

Philip Kelley的这篇博客文章解释了cURL不使用客户端机器的证书存储。我按照博客文章的建议创建了curl-ca-bundle的私有副本。然后配置Git使用它。我确定Git正在使用我的副本。如果我重命名副本;Git抱怨文件丢失。

我粘贴了我的证书,正如博客文章中提到的,我仍然得到“无法获得本地发行人证书”的消息。

我通过HTTPS克隆GitHub仓库来验证Git仍然在工作。

我看到的唯一不同于博客文章的地方是我的证书是根证书——没有链可以到达它。我的证书最初来自点击IIS8 IIS管理器链接“创建自签名证书”。也许这使得证书在某种程度上与cURL所期望的有所不同。

如何让Git/cURL接受自签名证书?


当前回答

Git配置——global http。sslVerify假

其他回答

我以前有过这个问题,并使用以下配置解决它。

(http“https://your.domain”) sslCAInfo = /道路/ /你/域/ priviate-certificate

由于git 2.3.1,您可以将https://your.domain放在http之后,以表明以下证书仅用于它。

我在Azure DevOps (Visual Studio)上也遇到过同样的问题。最后,我决定克隆我的回购使用SSH协议,因为我更喜欢它而不是禁用SSL验证。

你只需要生成一个SSH密钥,你可以这样做…SSH的文档

ssh-keygen

然后,在yout git主机上导入公钥(如Azure Devops, Github, Bitbucket, Gitlab等)。

我也遇到过这个问题。最终在MSDN博客的指导下得到了解决。

更新

实际上,你需要在git的证书文件curl-ca-bundel中添加证书。位于Git\bin目录下。

步骤

Open your github page in browser, and click over lock icon in address bar. In the opened little popup up navigate to 'view certificate' link, it will open a popup window. In which navigate to certificates tab (3rd in my case). Select the top node that is root certificate. And press copy certificate button in the bottom and save the file. In file explorer navigate Git\bin directory and open curl-ca-bundle.crt in text editor. Open the exported certificate file (in step 3) in text editor as well. Copy all of the content from exported certificate to the end of curl-ca-bundle.crt, and save.

最后检查状态。请注意备份curl-ca-bundle。CRT文件之前编辑,以保持安全。

使用makecert用于开发SSL的答案为我修复了这个问题。

我不知道为什么,但是IIS管理器中简单的“创建自签名证书”链接创建的证书并没有做到这一点。我遵循了创建和安装自签名CA根的链接问题中的方法;然后使用它为我的服务器颁发服务器身份验证证书。我在IIS中安装了它们。

这让我的情况与原始问题中引用的博客文章相同。一旦根证书被复制/粘贴到curl-ca-bundle中。CRT的git/curl组合是满意的。

在我的例子中,因为我已经为windows 7安装了ConEmu终端,它在C:\Program Files\Git\mingw64\ssl\certs.的安装过程中创建了ca-bundle

因此,我必须在终端上运行以下命令才能使其工作:

$ git config --global http.sslbackend schannel
$ git config --global http.sslcainfo /mingw64/ssl/certs/ca-bundle.crt

因此,我的C:\Program Files\Git\etc\gitconfig包含以下内容:

[http]
    sslBackend = schannel
    sslCAinfo = /mingw64/ssl/certs/ca-bundle.crt

另外,在安装Git时,我选择了与这里提到的相同的选项。

希望有帮助!