keyfil/教程/20250122-Clash安装及GitSSH使用代理教程.md
liuxiaohua cd0b30796f
All checks were successful
Publish to Confluence / confluence (push) Successful in 3m39s
♻️ [2025-02-10] 梳理项目结构
2025-02-10 09:21:02 +08:00

118 lines
5.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- Space: qifu -->
<!-- Parent: 后端技术&知识&规范 -->
<!-- Parent: 技术方案 -->
<!-- Parent: 基建 -->
<!-- Parent: 04-使用教程 -->
<!-- Title: 20250122-Clash安装及GitSSH使用代理教程 -->
<!-- Macro: :anchor\((.*)\):
Template: ac:anchor
Anchor: ${1} -->
<!-- Macro: \!\[.*\]\((.+)\)\<\!\-\- width=(.*) \-\-\>
Template: ac:image
Url: ${1}
Width: ${2} -->
<!-- Macro: \<\!\-\- :toc: \-\-\>
Template: ac:toc
Printable: 'false'
MinLevel: 2
MaxLevel: 4 -->
<!-- Include: 杂项/声明文件.md -->
<!-- :toc: -->
# 20250122-Clash安装及GitSSH使用代理教程
## Clash安装配置
### 下载 Clash
- 进入 [Clash官网][ClashDownload]
- 下载对应的客户端
- Windows可以直接下载[Clash.Verge_1.5.11_x64-setup.exe](https://picture.texous.cn/blog/20250122103244674.exe)
- 安装
### 配置
#### 订阅链接
- 点击订阅, 输入订阅链接, 点击导入
- ![](https://picture.texous.cn/blog/20250122103541177.png)
#### 配置服务模式及TUN模式(SSH代理需要)
- 点击设置, 开启服务模式和Tun模式
- ![](https://picture.texous.cn/blog/20250122103815705.png)
## 配置Git使用SSH代理
### 问题来源
> 当进行 SSH 连接时抛出 kex_exchange_identification: Connection closed by remote host如果你使用了代理工具那基本上为代理的问题。
- 可能出现错误的原因: 网络中断、不稳定等,端口连接失败(本地或代理的防火墙)
- 最小复现:选择一个无法连接的节点,或在连接途中切换网络环境(或节点)
- ![](https://picture.texous.cn/blog/20250122104133612.png)
### 解决方案
#### 不使用代理
- 不使用代理。如果是和 Github 进行交互可以选择 Https 方式进行。
- ```shell
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
```
#### 通过 443 端口链接 SSH
- 测试 443 端口是否可用
- 前提SSH 服务需要支持该端口,如 Github
- 大多数规则(或防火墙)都不会对 443 端口进行限制(基本上你能访问 Https 站点即代表 443 是放行的)
- 当然,在配置之前可以先测试 443 的连通性(注意:支持 443 端口的域名为 ssh.github.com 非 github.com
- ```shell
ssh -T -p 443 git@ssh.github.com
```
- 若如下输出,则表明连接成功
- ```shell
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
```
- 覆盖 SSH 的默认行为
- 确保刚才的测试指令可以连通 443 端口
- 编辑 ~/.ssh/configwin用户目录/.ssh即可无感切换端口连接 SSH
- 若无该配置文件,保存时会自动创建.(win: 直接新建 config 文件)
- 编辑 `config` 文件.(linux: `vi ~/.ssh/config`, win: 右键,记事本编辑)
- ```text
Host github.com
Hostname ssh.github.com
Port 443
User git
```
- 测试
- 注意这里使用的是原来的域名 github.com对使用来说无感知
- ```shell
$ ssh -T git@github.com
#- Hi USERNAME! You've successfully authenticated, but GitHub does not
#- provide shell access.
```
- 不同端口的连接(开启 TUN 模式,可在代理软件中查看相关连接)
- ![](https://picture.texous.cn/blog/20250122105125193.png) ![](https://picture.texous.cn/blog/20250122105137391.png)
- 至此教程结束
----
## 相关知识
### SSH known_hosts
- 当使用 SSH 连接新的服务时(如 ssh.github.comSSH 会展示目标服务的公钥指纹用于验证服务。当输入 yes 后,服务器公钥将会被保存至 ~/.ssh/known_hosts 中用于后续连接时的公钥验证
- ```shell
#- The authenticity of host '[ssh.github.com]:443 ([140.82.112.36]:443)' can't be established.
#- ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
#- This host key is known by the following other names/addresses:
#- ~/.ssh/known_hosts:32: github.com
#- Are you sure you want to continue connecting (yes/no/[fingerprint])?
```
- Github 提供的 SSH 密钥指纹,可添加至 known_hosts 文件中,避免在连接时手动验证(验证也仅在第一次)
### 终端代理 与 TUN 模式
- 通过 export http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890 可在终端设置 代理的环境变量
- 需要注意的是,一些命令如 SSH、PING 等由于自身实现,或传输层限制等无法使用终端代理,此时可以打开代理工具的 TUN 模式来解决。
- TUN 模式相当于给系统安装虚拟网卡,可以捕获所有类型的流量,即便代理只支持 TCP 或 UDP 的流量,如 ICMP 层的 PING。该模式是无感的可以快速的接管不支持 系统代理 的应用
## 总结
- 如果你之前一直使用代理来连接 SSH只是偶尔出现该情况那建议更换代理服务或暂时关闭代理直接连接。
## 参考
- [Using SSH over the HTTPS port](https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port)
- [解决使用代理clash 等)进行 SSH 连接(如 Github ssh key clone/push出现 kex_exchange_identification 错误](https://ksh7.com/posts/ssh-connection-errors/)
[ClashDownload]: https://clashcn.com/clashreleases