我在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接受自签名证书?


当前回答

错误

把失败 致命:无法访问 SSL证书问题:无法获得本地颁发者证书

原因

在本地机器上提交文件后,当本地Git连接参数过期时(例如HTTP更改为HTTPS),就会出现“push fail”错误。

解决方案

Open the .git folder in the root of the local directory Open the config file in a code editor or text editor (VS Code, Notepad, Textpad) Replace HTTP links inside the file with the latest HTTPS or SSH link available from the web page of the appropriate Git repo (clone button) Examples: url = http://git.[host]/[group/project/repo_name] (actual path) replace it with either url = ssh://git@git.[host]:/[group/project/repo_name] (new path SSH) url = https://git.[host]/[group/project/repo_name] (new path HTTPS)

其他回答

问题是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更容易配置,而且不太可能被防火墙阻止,这意味着失败的几率更小。

You might have a DNS issue and not a certificate issue, so before you disable SSL verification in your Git shell you should rule out a DNS problem. Cases such as these have been mentioned in Q&A forums such as https-issues-possibly-related-to-dns. If you are using WSL on Windows as your terminal, then you can try running sudo echo nameserver 8.8.8.8 > /etc/resolv.conf and then issue the git commands to see if that makes a difference. This does not seem to be a permanent DNS fix (lasting only the lifetime of your terminal session), but it could help you determine whether it is a DNS issue and not a certificate issue. You could also check this document on configuring your network to use a public DNS. Again, this is only to help you determine if your DNS settings might need adjusting in order to help resolve the certificate issues.

有一件事让我很困惑,那就是路径的格式(在我的Windows电脑上)。我最初是这样写的:

git config --global http.sslCAInfo C:\certs\cacert.pem

但是失败了,出现了“无法获得本地发行者证书”错误。

最终起作用的是:

git config --global http.sslCAInfo "C:\\certs\\cacert.pem"

解决了我的问题 Git配置——global http。sslBackend schannel

这对我很有用。我打开cmd行并运行以下命令。又拉了一下。

Git配置——global http。sslVerify假