Git pull 错误 gnutls_handshake() failed: Error in the pull function

Git pull 错误 gnutls_handshake() failed: Error in the pull function

I fiddled with the VPN a few days ago, but finally the configuration failed. Later, it was found that the local git and the remote warehouse could not be connected? ? git pull and git push have been encountering the following problems.
fatal: unable to access 'https://github.com/xxxxxx/': gnutls_handshake() failed: Error in the pull function.
Suspected that it may be a problem with the VPN, I turned off the VPN, even after uninstalling openvpn, I still can't connect. After searching the Internet, some said it was a VPN problem, some said that the proxy should be changed, and some said that openSSL should be used to recompile git; some luckier students would be fine by themselves every few days.
After two days of continuous tinkering, I slightly understood the cause of the error.

Below is an excerpt from StackOverFlow

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.

The reason is that GnuTLS cannot connect to the server. You can see it in the Depends of git below libcurl3-gnutls. We can replace gnutls with openssl and use ssl for transmission.

~$ apt show git
Package: git
Version: 1:2.32.0-1~ppa0~ubuntu18.04.1
Priority: optional
Section: vcs
Maintainer: Jonathan Nieder <[email protected]>
Installed-Size: 36.9 MB
Provides: git-completion, git-core
Depends: libc6 (>= 2.16), libcurl3-gnutls (>= 7.56.1), libexpat1 (>= 2.0.1), libpcre2-8-0 (>= 10.31), zlib1g (>= 1:1.2.0), perl, liberror-perl, git-man (>> 1:2.32.0), git-man (<< 1:2.32.0-.)

Recompile git using openssl instead of gnutls

This tutorial is relatively new, you can refer to this tutorial to modify the git deb package.

Because several Chinese posts using this method I found are slightly outdated, I am here to make some corrections to these older posts (you can refer to the above post).

Many old posts mentioned gksuhave been removed in the newer Ubuntu version, gksuwhich is to provide sudo permissions to the GUI. You can use vim to modify debian/controland debian/rule.

Use SSH remote repository

I got halfway through this method, and suddenly thought of a way to bypass this problem. The answer is in the last sentence of StackOverFlow's answer just now:

You can also just switch to SSH-based remotes, which will avoid this incompatibility altogether.

Cloning with HTTPS URLs

The https:// clone URLs are available on all repositories, regardless of visibility. https:// clone URLs work even if you are behind a firewall or proxy. When you git clone, git fetch, git pull, or git push to a remote repository using HTTPS URLs on the command line, Git will ask for your GitHub username and password.

Cloning with SSH URLs

SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and add the public key to your GitHub account. For more information, see “Connecting to GitHub with SSH.” When you git clone, git fetch, git pull, or git push to a remote repository using SSH URLs, you’ll be prompted for a password and must provide your SSH key passphrase.

When we clone the remote warehouse, we can use the SSH protocol for transmission, so that when we push, we will naturally use SSH to avoid the above problems. This method can only be used with your own repo.

Guess you like

Origin blog.csdn.net/inghoG/article/details/117927858