在这篇文章中,我将演示如何解决执行git clone
时出现的以下错误:
root@launch-advisor-20191120:/opt# git clone https://github.com/boylegu/SpringBoot-vue.git
Cloning into 'SpringBoot-vue'...
fatal: unable to access 'https://github.com/boylegu/SpringBoot-vue.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.
root@launch-advisor-20191120:/opt#
核心错误信息是:
fatal: unable to access 'https://github.com/boylegu/SpringBoot-vue.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.
2.环境
- Ubuntu 18.04.5 长期支持版
- Git版本:git版本2.17.1
3. 错误原因及解决方法
此错误意味着Git 无法与您尝试使用的服务器建立安全连接。您的 Git 版本使用 GnuTLS 库来设置 TLS(加密)连接,并且由于某种原因设置过程失败
这可能有几个原因。一个是您的服务器(您没有提到的服务器)正在使用一组不兼容的密码套件或 TLS 版本,并且没有可以选择的通用加密算法。也有可能有人通过 MITM 设备篡改了连接。
您正在使用的 Git 和 GnuTLS 版本应该可以在大多数标准服务器上正常工作。重新安装它不会有帮助。您可以尝试升级到较新版本的 Debian,或者您可以尝试使用 OpenSSL 针对某个版本的 libcurl 自行构建 Git。你也可以只切换到基于 SSH 的远程,这将完全避免这种不兼容。
从上述描述中我们可以确定这个问题是由 https/TLS/SSL 引起的,所以解决方法如下:
3.1 解决方案#1
最简单的解决方案是在执行时使用http
而不是:https
使用http协议:
git clone http://github.com/boylegu/SpringBoot-vue.git
而不是https协议:
git clone https://github.com/boylegu/SpringBoot-vue.git
3.2 解决方案#2
关闭https验证:
git config --global http.sslVerify false
如果您的 git 服务器使用自签名证书,那么使用该方法可以快速解决问题。
3.3 解决方案#3
用ssl重新编译本地git版本:(记得替换1.7.9.5
成你系统中实际的git版本。)
sudo apt-get update
sudo apt-get install build-essential fakeroot dpkg-dev
sudo apt-get build-dep git
mkdir ~/git-openssl
cd ~/git-openssl
apt-get source git
dpkg-source -x git_1.7.9.5-1.dsc
cd git-1.7.9.5