git - 在不禁用权威签名证书的情况下添加自签名 SSL 证书

标签 git ssl github

我有一个使用自签名证书通过 https 工作的公司 git 服务器。本地克隆包含两个远程 - 指向该服务器的原点,另一个指向 github。 默认情况下从原点 pull 失败:

$ git pull
fatal: unable to access 'https://user@code.example.com/git/fizzbuzz.git/': SSL certificate problem: self signed certificate

github 远程工作正常。

有两种经常建议的解决方案:

git config http.sslVerify false

这是个坏主意,建议在configure Git to accept a particular self-signed server certificate for a particular https remote :

git config http.sslCAInfo <downloaded certificate>.pem

它修复了从原点 pull ,但破坏了 github 远程:

$ git pull github
fatal: unable to access 'https://github.com/user/fizzbuzz.git/': SSL certificate problem: unable to get local issuer certificate

如何在不中断从 github 的 pull 的情况下从公司服务器进行 pull ?

最佳答案

如果您使用的是 Git 1.8.5+(2013 年 8 月),您可以 specify http directives per URL(!) .

在你的情况下:

git config --global http."https://code.example.com/".sslVerify false
#
# or, if not on default 443 port:
#
git config --global http."https://code.example.com:<aPort>/".sslVerify false

那只会为 code.example.com 禁用 SSL 验证,不适用于其他网址。

或者:

git config --global http."https://code.example.com/".sslCAInfo <downloaded certificate>.pem

同样的想法:sslCAInfo会指向 <downloaded certificate>.pem仅适用于 code.example.com网址。

可以在 Git 系统证书库中添加您的证书,其中 git-for-windows , 会在 C:\path\to\PortableGit-2.6.1-64-bit\usr\ssl\certs\ca-bundle.crt .
不过,这不是最佳做法,除非您必须分发其中包含内部证书的 Git 发行版。

关于git - 在不禁用权威签名证书的情况下添加自签名 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23807313/

相关文章:

GIT 扩展无法连接到远程,但 git bash 可以

python - 使用 Fabric 对 git 存储库的权限被拒绝

php - 如何在 Zend MVC 中实现 SSL

GitHub:我为什么要 fork ?

Jenkins GitHub 访问 token - 启用检查但不编写代码

带有 git 和 phpfog 的 Php 多数据库环境

git - 查找仅更改空格的提交

google-chrome - 忘记 Chrome 将哪个客户端证书用于 URL

ruby-on-rails - Rails 不通过 SSL 呈现 Assets (404 未找到错误)

git - merge 来自同一用户的提交在 GitHub 上出现两次