github: 服务器证书验证失败

github: server certificate verification failed

我刚刚在其中创建了一个 github 帐户和一个存储库,但是在尝试使用推荐 url 通过

创建本地工作副本时
git clone https://github.com/<user>/<project>.git

我收到类似

的错误

fatal: unable to access 'https://github.com/<user>/<project>.git': server certificate verification failed. CAfile: /home/<user>/.ssl/trusted.pem CRLfile: none

我在使用 Debian Jessie,我希望 Debian 和 GitHub 提供/依赖一系列普遍接受的 CA,但显然我的系统不信任 GibHub 的证书。

有什么简单的方法可以解决这个问题(没有经常推荐的 "GIT_SSL_NO_VERIFY=true" hack 和类似的解决方法)?

编辑:

附加信息:

编辑:

@VonC 关于 git https.sslCAinfo 选项的建议让我走上了正确的轨道——我刚刚将下载的 cacert.org CA 添加到我的 trusted.pem,现在git 不再抱怨了。

首先确保您在 /etc/ssl/certs 中的 Debian 上安装了证书。

如果没有,请重新安装它们:

sudo apt-get install --reinstall ca-certificates

package does not include root certificates开始,添加:

sudo mkdir /usr/local/share/ca-certificates/cacert.org
sudo wget -P /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt
sudo update-ca-certificates

确保您的 git 确实引用了那些 CA:

git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt

Jason C mentions another potential cause ():

It was the clock. The NTP server was down, the system clock wasn't set properly, I didn't notice or think to check initially, and the incorrect time was causing verification to fail.

Certificates are time sensitive.

您还可以禁用 SSL 验证(如果项目不需要 login/password 以外的高级别安全性),方法是键入:

git config --global http.sslverify false

享受git:)

也可以是自签名证书等,全局关闭SSL验证不安全。您可以安装证书,以便系统可以看到它,但证书应该是完全正确的。

或者您可以使用一次配置参数进行克隆,因此命令将是:

git clone -c http.sslverify=false https://myserver/<user>/<project>.git;

GIT会记住false值,你可以在<project>/.git/config文件中查看。

尝试使用 url 连接到存储库:http://github.com/<user>/<project>.git (http 除了 https)

在你的情况下,你应该像这样克隆:

git clone http://github.com/<user>/<project>.git

对我来说简单

sudo apt-get update

问题已解决。这是一个时钟问题,使用此命令它重置为当前 date/time 并且一切正常

另一个可能的原因是您机器的时钟未同步(例如 Raspberry Pi)。检查当前 date/time 使用:

$ date

如果日期and/or时间不正确,请尝试更新:

$ sudo ntpdate -u time.nist.gov

或者,在虚拟机上(例如 Ubuntu VirtualBox):

$ timedatectl set-ntp no
$ timedatectl set-time YYYY-MM-DD
$ timedatectl set-time HH:MM:SS
$ timedatectl set-ntp yes

尝试从 Linux 控制台的 Windows 子系统上的 Github 克隆存储库时,我也遇到了这个错误:

fatal: unable to access 'http://github.com/docker/getting-started.git/': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

@VonC 在此线程上提供的解决方案对我不起作用。

这个Fabian Lee's article的解决方案为我解决了:

openssl s_client -showcerts -servername github.com -connect github.com:443 </dev/null 2>/dev/null | sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p'  > github-com.pem
cat github-com.pem | sudo tee -a /etc/ssl/certs/ca-certificates.crt

我遇到了类似的问题并收到了错误消息:

fatal: unable to access XXXX server certificate verification failed. CAfile: none CRLfile: none

当我尝试连接到我的常规(工作中!)git实验室服务器时突然发生,SSL 使用 letsencrypt 创建,来自 git 在 WSL2 ubuntu 下。

从浏览器访问服务器没有问题,使用 https://www.sslshopper.com/ssl-checker.html

等工具检查时 SSL 链似乎正常

您需要更新您的 CA 证书。

sudo apt update
sudo apt upgrade
sudo apt-get install --reinstall ca-certificates
sudo update-ca-certificates


# now it should work perfectly
git pull

可能是因为:
https://techcrunch.com/2021/09/21/lets-encrypt-root-expiry/

遇到此类错误时对我有用的方法(对我来说 gitlab 发生过):

fatal: unable to access 'https://github.com/<user>/<project>.git': server certificate verification failed. CAfile: /home/<user>/.ssl/trusted.pem CRLfile: none

是从网站的证书页面获取.pem文件(点击url左边的锁图标即可访问),直接复制到文件夹/etc/ssl/certs/.从那里,git 能够再次与 gitlab 互动。

对我来说,只需删除 sudo 就解决了。

我正在尝试 sudo git clone ...,只是 git clone 成功了。