我在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默认使用“Linux”加密后端。

从Git for Windows 2.14开始,您现在可以配置Git使用内置的Windows网络层channel作为加密后端。这意味着它将使用Windows证书存储机制,您不需要显式地配置curl CA存储机制:https://msdn.microsoft.com/en-us/library/windows/desktop/aa380123(v=vs.85).aspx

执行:

git config --global http.sslbackend schannel

这应该会有所帮助。

在Windows上安装git时,使用通道是现在的标准设置,如果可能的话,建议不要通过SSH或更多的方式签出存储库,因为https更容易配置,而且不太可能被防火墙阻止,这意味着失败的几率更小。

其他回答

kiddailey我认为非常接近,但是我不会禁用ssl验证,而是只提供本地证书:

在Git配置文件中

[http]
    sslCAinfo = /bin/curl-ca-bundle.crt

或者通过命令行:

git config --global http.sslCAinfo /bin/curl-ca-bundle.crt

我也遇到过这个问题。最终在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文件之前编辑,以保持安全。

在运行composer update/install之前使用此命令:

git config --global http.sslverify false

从此链接下载证书: https://github.com/bagder/ca-bundle 将其添加到C:\Program Files\Git\bin和C:\Program Files\Git\mingw64\bin

然后尝试如下代码:git clone https://github.com/heroku/node-js-getting-started.git

我在使用visual studio时出现了这个错误。当您在Visual Studio选项窗口中将加密网络提供程序设置设置为OpenSSL时,就会发生这种情况。当我将设置更改为安全通道时,它为我解决了这个问题。这个设置一定是在我升级我的VS时为我设置的。