others-How to solve 'gnutls_handshake() failed' error when doing 'git clone' from github.com ?

1. Purpose

In this post, I would demo how to solve the following error when doing git clone from github.com:

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#

The core error message is:

fatal: unable to access 'https://github.com/boylegu/SpringBoot-vue.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.

2. The environment

  • Ubuntu 18.04.5 LTS
  • Git version:git version 2.17.1

3. The solution

What does the error mean? Here is an answer from bk2204 :

This error means that Git cannot establish a secure connection to the server you’re trying to use. Your version of Git uses the GnuTLS library to set up TLS (encrypted) connections, and for some reason that setup process is failing

This could be for a couple of reasons. One is that your server (which one you haven’t mentioned) is using an incompatible set of cipher suites or TLS versions, and there’s no encryption algorithms in common that can be chosen. It’s also possible that you have someone tampering with the connection via a MITM device.

The version of Git and GnuTLS you’re using should work just fine with most standard servers. Re-installing it won’t help. You can try upgrading to a newer version of Debian, or you can try building Git yourself against a version of libcurl using OpenSSL. You can also just switch to SSH-based remotes, which will avoid this incompatibility altogether.

So, this problem is caused by the https/TLS/SSL , so the solution are as follows:

3.1 Solution #1

The simplest solution is to use http instead of https when doing git clone:

Replace:

 git clone https://github.com/boylegu/SpringBoot-vue.git

with this:

 git clone http://github.com/boylegu/SpringBoot-vue.git

Now run the command:

root@launch-advisor-20191120:/opt#  git clone http://github.com/boylegu/SpringBoot-vue.git
Cloning into 'SpringBoot-vue'...
warning: redirecting to https://github.com/boylegu/SpringBoot-vue.git/
remote: Enumerating objects: 503, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 503 (delta 6), reused 0 (delta 0), pack-reused 488
Receiving objects: 100% (503/503), 32.34 MiB | 15.97 MiB/s, done.
Resolving deltas: 100% (151/151), done.
root@launch-advisor-20191120:/opt#

It works!!!

3.2 Solution #2

Turn off the https verification:

git config --global http.sslVerify false

It will work if your git server uses a self-signed certification.

3.3 Solution #3

Recompile the local git version with ssl: (Remember to replace 1.7.9.5 with the actual version of git in your system.)

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

Now It’s working!

4. Summary

In this post, I demonstrated how to solve the git clone error, you can try as mine. I recommend to use the solution 1, it’s simple. That’s it, thanks for your reading.