git SSL certificate problem: self-signed certificate in certificate chain 解决办法
git clone https://xxxxx.git
Cloning into 'workflow-java'...
fatal: unable to access 'https://xxxx.git/': SSL certificate problem: self-signed certificate in certificate chain
在 Windows 系统中关闭 Git 的 HTTPS SSL 证书验证(不推荐长期使用,仅限临时解决证书问题),可通过以下步骤操作:
方法 1:全局禁用 SSL 验证(影响所有仓库)
- 打开命令提示符(CMD)或 Git Bash
- 执行命令:
bash复制代码
git config --global http.sslVerify false
方法 2:仅针对当前仓库禁用 SSL 验证
- 进入项目根目录
- 执行命令:
bash复制代码
git config http.sslVerify false
恢复 SSL 验证
重新启用验证(安全推荐):
bash复制代码
# 全局恢复
git config --global --unset http.sslVerify
# 或直接设为 true
git config --global http.sslVerify true# 仅当前仓库恢复
git config --unset http.sslVerify
注意事项
- 安全风险:禁用 SSL 验证会使连接易受中间人攻击,仅限临时测试环境使用。
- 推荐替代方案:
- 信任自签名证书:将证书添加到 Git 的信任列表
bash复制代码
git config --global http.sslCAInfo "C:\path\to\your\ca-cert.pem"
- 更新系统根证书:通过 Windows 证书管理器安装证书(
certmgr.msc
)。
- 信任自签名证书:将证书添加到 Git 的信任列表
常见问题排查
- 代理问题:如果使用代理,确保其证书有效:
bash复制代码
# 查看当前代理设置 git config --global --get http.proxy
- 清除缓存:
bash复制代码
git credential-manager reject https://github.com # 清除凭据
重要提示:生产环境务必保持
http.sslVerify=true
,禁用验证仅作为临时手段。