当前位置:   article > 正文

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

github ssh nc代理无用

最近不知道发生了什么,通过 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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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

[user]
	signingkey = 55C1A242B0F517C4
	email = wuweijie@apache.org
	name = 吴伟杰
[commit]
	gpgsign = true
[http]
	proxy = socks://127.0.0.1:1089
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

既然用的是 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
  • 1
  • 2

配置完后再试试:

% 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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

问题解决!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/783473
推荐阅读
相关标签
  

闽ICP备14008679号