致命错误:无法访问“.....”:gnutls_handshake()失败:握手失败。

33

我过去几个月一直在使用Git。最近当我尝试克隆或推送时,一直出现这个错误。我在互联网上进行了研究,但到目前为止没有解决方案适用于我。有人有什么想法吗?

外部笔记:现在我搬到了不同的国家,在我之前的地方它完美地工作。 Git版本:2.11.0,操作系统:Debian GNU/Linux 9.11(stretch)

错误:

git push
fatal: unable to access 'https://**************/': gnutls_handshake() failed: Handshake failed

你是否在一个封锁加密连接的国家?因为看起来就是这种情况。 - bk2204
@bk2204 - 目前我在印度。如果是因为这个原因,有什么解决方案吗? - Harish Kanna
这也可能是TLS不兼容的问题。您能否编辑您的问题,指出您正在使用的操作系统和Git版本? - bk2204
@bk2204 - 重新安装git是个好主意吗?重新安装后会遇到同样的问题吗? - Harish Kanna
7个回答

45

这是在Ubuntu服务器14.04.x上解决此问题的解决方案。

1、编辑文件:

sudo nano  /etc/apt/sources.list

2,添加到文件 sources.list 中

deb http://security.ubuntu.com/ubuntu xenial-security main
deb http://cz.archive.ubuntu.com/ubuntu xenial main universe

3,运行更新命令,并将CURL更新到新版本

apt-get update && apt-get install curl

4、检查版本(可选):

curl -V
Response :

curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets 

5、测试与Bitbucket的连接(可选)

GIT_CURL_VERBOSE=1 git ls-remote https://bitbucket.org/
Response:


* Closing connection 0
fatal: repository 'https://bitbucket.org/' not found

完成了。


4
最佳答案!问题是关于修复git的http pull/push - 而不是如何使用SSH密钥。 - Alexander Goncharov
2
和作者遇到了同样的问题。这个解决方案对我有用。非常感谢! - Mario Werner
1
在完整的桌面系统上,升级curl到新版本会导致卸载许多依赖包并破坏其他功能。此外,如果这个技巧对您有效,请在安装新的curl版本后立即删除apt源的编辑,并且在执行apt-get upgrade或等效操作之前不要这样做! - RJVB

31

我在使用Ubuntu 14.04 LTS时也遇到了这个问题。最快的解决方法是使用ssh而不是https。以下是替换https为ssh的步骤:

  1. Generate ssh key using ssh-keygen on the server.

  2. Copy public key from generated id_rsa.pub file from step 1 and add it at following links depending on repository host -

    Bitbucket - https://bitbucket.org/account/settings/ssh-keys/

    Github - https://github.com/settings/ssh/new

    Gitlab - https://gitlab.com/profile/keys

  3. Now run following command to test authentication from server command line terminal

    Bitbucket

    ssh -T git@bitbucket.org
    Github
    ssh -T git@github.com
    Gitlab
    ssh -T git@gitlab.com

  4. Go to repo directory and open .git/config file using emac or vi

  5. Replace remote "origin" url (which starts with https) with following -

    For Bitbucket - git@bitbucket.org:<username>/<repo>.git

    For Github - git@github.com:<username>/<repo>.git

    For Gitlab - git@gitlab.com:<username>/<repo>.git


4
这是迄今为止最简单的解决方案。回答写得非常好。 - Alex Egli
1
这对我有用,但我必须使用ssh://git@bitbucket.org...... - tavis
我刚刚执行了这个命令 'ssh -T git@gitlab.com' 并在连接提示中选择了是。它被添加并开始建立连接。 - prash

11
这个错误表示Git无法与您尝试使用的服务器建立安全连接。您使用的Git版本使用GnuTLS库来建立TLS(加密)连接,由于某种原因,该设置过程失败。
可能有几种原因导致这种情况发生。一个原因是您的服务器(您没有提到哪一个)正在使用不兼容的密码套件或TLS版本,并且没有公共的加密算法可以选择。还有可能是您的连接被通过MITM设备篡改了。
您正在使用的Git和GnuTLS版本应该可以与大多数标准服务器正常工作。重新安装不会有所帮助。您可以尝试升级到更新的Debian版本,或者尝试使用OpenSSL构建Git自己的libcurl版本。您也可以切换到基于SSH的远程,以完全避免此不兼容性问题。

1
有一个开源项目可以帮助解决这个问题 - https://github.com/paul-nelson-baker/git-openssl-shellscript。当Bitbucket突然删除密码并破坏了我在旧的Debian盒子上的git时,它为我节省了很多时间。 - Chen A.
1
运行 shell 脚本让我有噩梦。切换到 SSH 远程更好。 - Chhorn Elit

3
这可能只是问题的一部分。 其他https网站怎么样? 你是如何连接到互联网的? 你的git副本可以通过VPN访问吗?
为什么我要问?我遇到了同样的问题: Git在运行Windows 10 Hyper-X托管的Ubuntu 22.04虚拟机中使用。 VM通过默认开关(NAT)连接到Internet,并共享主机的OpenConnect VPN连接。
有一天,git无法从位于私有网络中且可通过VPN访问的远程存储库中提取。症状与您的相似:
握手失败
经过一些调查,我发现了以下事实:
所有可通过VPN访问的https资源都可以在guest的默认预设下ping通,但无法建立与它们的Https连接 其他未受VPN保护的https资源是可达的,正常工作 当尝试使用Firefox浏览器连接到https资源时,在OpenConnect-GUI VPN客户端日志中发现了一些错误报告:OpenConnect Log window 之后,我尝试追踪到远程 Git 存储库的路径: tracepath-screenshot
developer@Ubuntu-VM:~$ tracepath **.**.167.240 -n
 1?: [LOCALHOST]                      pmtu 1500
 1:  172.18.224.1                                          0.485ms 
 1:  172.18.224.1                                          0.386ms 
 2:  172.18.224.1                                          0.227ms pmtu 1290
 2:  **.**.254.9                                          38.242ms 
 3:  **.**.30.14                                          32.438ms 
 4:  **.**.167.240                                        32.136ms reached
     Resume: pmtu 1290 hops 4 back 4 

我注意到屏幕右侧有一些“pmtu”字符串和最后的“Resume”提示。因此,我决定检查我的网络接口的MTU预设值:ifconfig-screenshot
developer@Ubuntu-VM:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.227.200  netmask 255.255.240.0  broadcast 172.18.239.255
        inet6 fe80::d1b:9e02:3919:d75b  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:19:76:00  txqueuelen 1000  (Ethernet)
        RX packets 56234  bytes 311928403 (311.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13927  bytes 1148583 (1.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

如您所见,接口eth0的MTU为1500(...当前VPN隧道太大了)。
当我将eth0的MTU更改为1290时,如 tracepath 实用程序建议的那样:
sudo ifconfig eth0 mtu 1290

我的问题已经解决了。(MTU 还必须在 Ubuntu 网络设置页面中更改,以实现永久生效)
受益!
还可以阅读:Windows WSL: Git and gnutls_handshake() failed

这对我有用,Ubuntu 20.04。 - panoet
谢谢你提出的建议,可能与使用Git进行源代码检出无关。 - undefined

2

我遇到了同样的错误。

您可以尝试使用Paul N. Baker的shell脚本将git编译为OpenSSL而不是gnutls。

  1. 创建file.sh
  2. 将链接中的代码复制到此文件中
  3. 为此文件赋予权限:chmod a+x file.sh
  4. 运行:sudo ./file.sh

这个shell脚本对我有用。


2
如果您正在使用Ubuntu 20.04作为我的操作系统,并且使用个人电脑(未配置代理),那么只需将gnutls-bin更新到最新版本即可。
sudo apt-get install gnutls-bin

0

我通过计算得出

git config --global --unset https.proxy
git config --global --unset http.proxy 

即使我尽力了

git config --global --get https.proxy
git config --global --get http.proxy 

不要显示任何结果,但取消 https.proxy 仍然有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接