[英]Git clone from gitlab fails on linux, while working in Windows git bash
我是 Linux 的新手,剛剛安裝了 Lubuntu 並遇到了問題 - 當我試圖從我公司的 git 克隆我的遠程工作存儲庫時:
$ sudo git clone https://path/to/repo.git
我不斷收到錯誤:
Cloning into 'repo'...
fatal: unable to access 'https://path/to/repo.git/': server certificate verification failed. CAfile: none CRLfile: none
我知道它提到了證書,但我沒有任何證書。 在此之前,我在 windows 上工作,並且能夠在沒有任何證書的情況下簡單地克隆 git 這個 repo。
此錯誤表示 git 客戶端無法驗證證書鏈或根的完整性。 解決此問題的正確方法是確保來自遠程存儲庫的證書有效,然后將其添加到客戶端系統。
我建議的第一件事是簡單地更新系統已知的根 CA 列表,如下所示。
# update CA certificates
sudo apt-get install apt-transport-https ca-certificates -y
sudo update-ca-certificates
如果您正在處理長時間未更新的系統,這可能會有所幫助,但當然不會解決私有證書的問題。
如果您將來自遠程 git 服務器的證書添加到本地檢查的證書列表中,來自 git 客戶端的錯誤將得到解決。 這可以通過使用 openssl 從遠程主機提取證書來完成:
openssl s_client -showcerts -servername git.mycompany.com -connect git.mycompany.com:443 </dev/null 2>/dev/null | sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p' > git-mycompany-com.pem
這將獲取“https://git.mycompany.com”使用的證書,並將內容復制到名為“git-mycompany-com.pem”的本地文件中。
If this host only has access to the git server via a web proxy like Squid, openssl will only be able to leverage a squid proxy if you are using a version of OpenSSL 1.1.0 and higher. 但是,如果您使用的是舊版本的 OpenSSL,那么您需要使用諸如 socat 之類的東西在本地綁定到端口 4443,並通過 squid 代理流量並到達最終目的地來解決此限制。
# install socat
sudo apt-get install socat -y
# listen locally on 4443, send traffic through squid "squidhost"
socat TCP4-LISTEN:4443,reuseaddr,fork PROXY:squidhost:git.mycompany.com:443,proxyport=3128
然后在另一個控制台中,告訴 OpenSSL 從 localhost 的 4443 端口拉取證書。
openssl s_client -showcerts -servername git.mycompany.com -connect 127.0.0.1:4443 </dev/null 2>/dev/null | sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p' > git-mycompany-com.pem
無論是通過代理還是直接連接,您現在都可以在名為“git-mycompany-com.pem”的文件中獲得遠程證書列表。 此文件將包含證書、其中間鏈和根 CA 證書。 下一步是讓 git 客戶端在連接到 git 服務器時考慮這一點。 這可以通過將證書添加到原始錯誤中提到的文件來完成,在這種情況下,對所有用戶進行全局更改,或者可以將其添加到單個用戶的 git 配置中。
** 全局添加 **
cat git-mycompany-com.pem | sudo tee -a /etc/ssl/certs/ca-certificates.crt
**為單個用戶添加**
git config --global http."https://git.mycompany.com/".sslCAInfo ~/git-mycompany-com.pem
它默默地將以下幾行添加到 ~/.gitconfig
[http "https://git.mycompany.com/"]
sslCAInfo = /home/user/git-mycompany-com.pem
避免跳過 SSL 認證驗證的解決方法。 僅使用它們來快速測試證書是否是根本問題,然后使用上面的部分來解決問題。
git config --global http.sslverify false
export GIT_SSL_NO_VERIFY=true
我知道已經有答案了。 僅對於那些使用私有網絡(例如 Zscaler 左右)的人來說,如果您的 rootcert 需要更新,則可能會出現此錯誤。 如果在 Windows 機器上使用 WSL,這里有一個關於如何實現此更新的解決方案:
#!/usr/bin/bash
# I exported the Zscaler certifcate out of Microsoft Cert Manager. It was located under 'Trusted Root Certification > Certificates' as zscaler_cert.cer.
# Though the extension is '.cer' it really is a DER formatted file.
# I then copied that file into Ubuntu running in WSL.
# Convert DER encoded file to CRT.
openssl x509 -inform DER -in zscaler_cert.cer -out zscaler_cert.crt
# Move the CRT file to /usr/local/share/ca-certificates
sudo mv zscaler_cert.crt /usr/local/share/ca-certificates
# Inform Ubuntu of new cert.
sudo update-ca-certificates
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.