SSH 常见问题

本文最后更新于:2024年9月8日 晚上

ClashX Pro 开启增强模式后 Git 连接不上 GitHub

1
$ ssh -T git@github.com  <br>kex_exchange_identification: Connection closed by remote host  <br>Connection closed by 28.0.0.102 port 22

增强模式是利用 TUN ,创建虚拟网卡改路由表优先走这块虚拟网卡接管所有流量。IP 28.0.0.101 是虚拟 IP,目的是为了接管系统流量。

问题原因

这个问题的原因就是某些节点因为安全问题禁用了 22 端口,而 SSH 默认使用的就是 22 端口,因此连接就会被拒绝。解决方法就是把 22 端口换成 443 端口,即通过 HTTPS 端口建立的 SSH 连接。

解决方案

  1. 测试通过 HTTPS 端口的 SSH 是否能连接,也就是 SSH 能否通过 443 端口连接到 git@ssh.github.com
1
2
3
4
5
6
7
8
9
10
```shell
$ ssh -vT -p 443 git@ssh.github.com
OpenSSH_8.6p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/gan/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to ssh.github.com port 443.
debug1: Connection established.

可以看到连接没有问题。
2. 在 SSH 配置文件中设置此行为。

1
2
3
4
Host github.com  
Hostname ssh.github.com
Port 443
User git
  1. 验证
1
2
$ ssh -T git@github.com   
Hi LuShan123888! You've successfully authenticated, but GitHub does not provide shell access.

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