DEBUG.WIKI
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证

解决 Linux Git 报错 SSL certificate problem 证书校验失败修复

排查 git clone 提示 fatal: unable to access ...: SSL certificate problem: self signed certificate in certificate chain,配置 http.sslCAInfo 或安装自签根证书。

问题现象

在终端拉取或提交代码时,Git 抛出 SSL 证书校验阻断:

fatal: unable to access 'https://gitlab.example.com/org/repo.git/': 
SSL certificate problem: self signed certificate in certificate chain
# 或者提示:
# SSL certificate problem: unable to get local issuer certificate

触发根因

企业内部搭建的私有 GitLab 或 Gitea 代码平台采用了内部自签名 SSL 证书。Git 客户端底层依赖系统的 OpenSSL 信任库校验服务端公钥证书链,由于本地信任库中缺少该自签 CA 的根证书,Git 出于安全防范中间人攻击(MITM)而强制中断克隆。

解决步骤

方案一:为当前特定仓库指定私有 CA 证书文件(推荐安全方案)

将企业的根证书 my_ca.crt 拷贝到本地并绑定至 Git 配置:

git config --global http."https://gitlab.example.com/".sslCAInfo /etc/ssl/certs/my_ca.crt

仅针对该私有域名信任私有证书,不对全网其他域名放宽安全边界。

方案二:临时关闭单次 Git 操作的 SSL 证书校验(临时排障)

使用 -c http.sslVerify=false 参数:

git -c http.sslVerify=false clone https://gitlab.example.com/org/repo.git

验证确认

重新触发代码克隆:

git clone https://gitlab.example.com/org/repo.git

控制台成功打印 Cloning into 'repo'... Receiving objects: 100%,代码拉取顺利完成。