Git遇到SSL证书问题

Git遇到SSL证书问题

问题现象

git clone/push时,出现:server certificate verification failed. CAfile: none CRLfile: none

解决方案

先要了解一下Git配置中和SSL有关的几个关键属性:

  • http.sslVerify:该属性用于指定是否验证SSL证书,默认值为true,表示验证证书。
  • http.sslCAInfo:该属性用于指定SSL证书的位置,提供自定义的CA证书进行验证。
  • http.sslCAPath:该属性用于指定SSL证书的路径,提供自定义的CA证书进行验证。

临时规避

使用ssh方式克隆。或者临时禁用 ssl 验证:

export GIT_SSL_NO_VERIFY=1
或者
git -c http.sslVerify=false clone https://github.com/username/repo.git

永久规避

git config --global http.sslverify false
git config --global https.sslverify false

永久解决

安装git托管仓库的SSL证书。这里是装github的证书:

# 1. 获取GitHub的SSL证书,这条命令输出中的-----BEGIN CERTIFICATE-----和-----END CERTIFICATE-----之间的就是SSL证书
openssl s_client -showcerts -connect github.com:443 </dev/null
# 2. 保存GitHub的SSL证书到/usr/local/share/ca-certificates中(最好不要放在/etc/ssl/certs/ca-certificates.crt中,这个是系统ssl自带的)
mv github.crt /usr/local/share/ca-certificates/github.crt
# 3. 更新系统SSL证书
update-ca-certificates

其中如果第2步也可以这样来单次生效:

git -c http.sslCAInfo=/path/to/github.crt clone https://github.com/username/repo.git # 放在文件中
git -c http.sslCAPath=/path/to/certificates clone https://github.com/username/repo.git # 放在目录中

本文作者:3to4

本文链接:https://www.cnblogs.com/3to4/p/18651470

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @ 2025-01-04 09:28  3的4次方  阅读(189)  评论(0编辑  收藏  举报