SSL Cert error of git operations via https

對 remote git repository 存取,可以透過 ssh 或 https,有時候用 https 的時候會遇到 Error

原因

如果是透過 https 來對 remote repository 做操作,例如 git clone https://git.domain.com/xxoo.git,有時候會有類似 “SSL certificate problem: unable to get issuer certificate” 這樣的訊息出現。主因是當透過 https 時,git client 會去檢查 server 的 ssl 憑證簽署單位是不是在本機的清單當中。所以如果是用 self-signed 的 ssl 憑證,或者是簽屬單位沒在清單中,就會有這個錯誤出現。

最懶惰的解決方式

$ git config --global http.sslverify false

但這個方式等於關閉所有的 ssl 驗證,並不是很安全。

正常的解決方式

因為公司裡面用 godaddy 的憑證,所以就以 godaddy 的當作例子。

  • Linux (用 ubuntu 16.04 當例子)
    $ wget https://certs.godaddy.com/repository/gdig2.crt.pem # from Godaddy Cert repository https://certs.godaddy.com/repository
    $ sudo mv gdig2.crt.pem /usr/local/share/ca-certificates/gdig2.crt
    $ sudo update-ca-certificates
    
  • windows git bash console
    # 先從 Godaddy Cert repository https://certs.godaddy.com/repository 下載 https://certs.godaddy.com/repository/gd_bundle-g2.crt
    $ git config --global http.sslCAInfo PATH_TO_DOWNLOAD_CRT_FILE" #要移除設定的話可以 git config --global --unset http.sslCAInfo