抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

鉴于国情 Github 时好时坏,现在 Git 推送又只能通过ssh协议,因此本文讲述如何在不同系统中为 ssh 协议配置代理

最常见错误即 kex_exchange_identification: Connection closed by remote host

一、配置

请自行准备代理,下文配置其中的ip和端口修改成你自己代理的参数

1.Windows下

修改C:\Users\${your username}\.ssh目录下的config文件,若没有则新建

1
2
3
4
5
Host github.com                                                                                                          
Hostname ssh.github.com
Port 443
User git
ProxyCommand connect -S 127.0.0.1:7890 %h %p

2.类Unix系统

例如Linux、MacOS、Windows的Wsl2等等

修改~/.ssh目录下的config文件,若没有则新建

1
2
3
4
5
Host github.com
Hostname ssh.github.com
Port 443
User git
ProxyCommand nc -v -x 172.28.208.1:7890 %h %p

二.验证

Windows下打开 git bash,其他系统使用终端执行 ssh -T git@github.com

1
2
3
4
5
6
$ ssh -T git@github.com
The authenticity of host '[ssh.github.com]:443 (<no hostip for proxy command>)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443' (ECDSA) to the list of known hosts.
Hi seepine! You've successfully authenticated, but GitHub does not provide shell access.

若出现错误,则删除.ssh目录中known_hosts文件重试

评论