ssh因不明原因被重定向为了https

_记一次,和 chatgpt 合伙解决的一个大坑_:在对 SSH 协议的 git 仓库进行克隆时,出现与 HTTPS 协议相关的错误。而公司 git 仓库并不支持 https,所有无法拉取成功。开始一直是以为 ssh 密钥的问题,但并不是,这个错误隐藏在更加深的地方…

1
2
3
4
$ git clone ssh://git@220.167.101.49:18389/FE-ZeroToOne/fch-h5/fch-h5-spa.git

> Cloning into 'fch-h5-spa'...
> fatal: unable to access 'https://220.167.101.49:18389/FE-ZeroToOne/fch-h5/fch-h5-spa.git/': error:1408F10B:SSL routines:ssl3_get_record:wrong version number
1
2
3
4
5
6
7
8
9
10
11
12
13
// 这是出现问题的电脑的git配置
$ git config --global -l
user.email=1324022569@qq.com
user.name=bazijun
http.sslverify=false
url.https://.insteadof=ssh://git@
core.autocrlf=false

// 这是没问题电脑的git配置
git config --global -l
user.name=bazijun
user.email=1324022569@qq.com
core.autocrlf=false

有问题的电脑上的 git 配置多出这两行:

1
2
http.sslverify=false
url.https://.insteadof=ssh://git@
  • 第一行 http.sslverify=false 关闭了 SSL 验证,这通常不推荐,除非你确定你要连接的服务器是可信的。这可能变得很危险,因为它会使你容易受到中间人攻击。
  • 第二行url.https://.insteadof=ssh://git@告诉了 Git 在尝试克隆或者拉取以”ssh://git@”开头的 URL 时改为使用 HTTPS 协议。这便解释了为什么当尝试通过 SSH 协议克隆时,最终却出现与 HTTPS 协议相关的错误。

删除这两行配置即解决成功

1
2
git config --global --unset http.sslverify
git config --global --unset url.https://.insteadof

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!