git config 配置了 http.proxy 代理使用 ssh 仍然超时

博主遇到通过SSH协议操作GitHub仓库时出现超时的问题,而HTTPS协议则正常。检查Git配置和代理设置后,问题依然存在。为解决此问题,博主参考StackOverflow上的建议,在.ssh/config中添加了ProxyCommand配置,利用nc(netcat)通过SOCKS代理与GitHub通信,最终成功克隆仓库。
摘要由CSDN通过智能技术生成

最近不知道发生了什么,通过 ssh 协议对 GitHub 仓库进行任何操作都会超时,无法推拉代码。但使用 https 协议从 GitHub 拉代码正常。
因为我的账号配置了 2FA,还是需要搞清楚为什么 ssh 协议无法正常操作 GitHub 的 remote。

之前都没问题的,但现在操作总是超时,没有成功过:

% git clone --depth=1 git@github.com:TeslaCN/shardingsphere.git
Cloning into 'shardingsphere'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

检查我的 Git 配置,socks 代理经过验证仍然科学,感觉不是代理的问题。
.gitconfig

[user]
	signingkey = 55C1A242B0F517C4
	email = wuweijie@apache.org
	name = 吴伟杰
[commit]
	gpgsign = true
[http]
	proxy = socks://127.0.0.1:1089

既然用的是 ssh,能不能在 OpenSSH 工具上做点手脚?

Google 了一下找到了 stack overflow 的一个帖子:
Connect with SSH through a proxy

可以对 github.com 这个 Host 使用 nc (netcat) 勾搭上我的 socks 代理。nc 应该也支持 https 协议的代理(本人环境是 Ubuntu 20.04,其他环境可以参考 stack overflow 的回答)。
.ssh/config 增加以下内容:

Host github.com
ProxyCommand nc -x 127.0.0.1:1089 %h %p

配置完后再试试:

% git clone --depth=1 git@github.com:TeslaCN/shardingsphere.git
Cloning into 'shardingsphere'...
remote: Enumerating objects: 15571, done.
remote: Counting objects: 100% (15571/15571), done.
remote: Compressing objects: 100% (8963/8963), done.
remote: Total 15571 (delta 6689), reused 9998 (delta 3544), pack-reused 0
Receiving objects: 100% (15571/15571), 43.18 MiB | 1.21 MiB/s, done.
Resolving deltas: 100% (6689/6689), done.

问题解决!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wuweijie@apache.org

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值