connect to host github.com port 22: Connection timed out

576 阅读1分钟

问题描述

回老家后,推送git发现推不上去了。

$ git fetch
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.

浏览器可以正常访问Google和github,说明代理没有问题。
配置HTTP_PROXY等变量后,可以curl www.google.com,因此命令行环境应该也没有问题。

git config --global http.proxy 'http://127.0.0.1:7890' 
git config --global https.proxy 'http://127.0.0.1:7890'

尝试了配置git代理还是没有用。

解决方法

打开tun模式

取消命令行中配置的任何代理,然后打开tun模式 image.png

ssh.github.com(不用代理)

在这之前我没有使用过这个域名。
打开config进行配置。

# powershell中执行(vscode)
code $home/.ssh/config

配置大概如下,主要的改动就在于这个HostName改成ssh.github.com。
我看到很多帖子说使用443端口,但是我试过不用改也能访问。

Host github.com
  HostName ssh.github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/github/id_ed25519