github 在 clone 源码时有两种协议可用,分别是 SSH 协议和 HTTPS 协议,SSH 协议会使用 22 端口,HTTPS 协议使用的是 443 端口。
例如:
git .com:hyang0/ip_notes.git
如果 SSH 协议在使用中抽风,可以试试将 22 端口换成以下配置。可以在 ~/.ssh/config 中更换 SSH 端口:
Host github.com
Hostname ssh.github.com
Port 443
User git
这里使用 443 代替原 22 端口,在执行 git clone 、git push 时仍然可以使用 ssh 协议。git clone 项目时,使用的还是 ssh 协议:
git clone git@github.com:hyang0/ip_notes.git
这种方式是没有使用代理的,使用的是原生 SSH 协议,如果需要使用代理,可以对 ~/.ssh/config 做如下改动:
Host github.com
HostName github.com
User git
ProxyCommand connect -S 127.0.0.1:1080 %h %p
类似的配置有:
Host github.com
User git
ProxyCommand nc -v -x 127.0.0.1:1086 %h %p
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 22
ProxyCommand connect -S 127.0.0.1:7890 %h %p
-S 表示使用socks5代理,如果是http代理则为-H。connect 工具是 windows 下的 git 自带的, 一般在 /mingw64/bin/connect 下面。
which connect
/mingw64/bin/connect
如果不想使用 SSH 配置,也可以直接使用 HTTPS 协议。在 git-bash 下设置 http_proxy, https_proxy 即可:
# ~/.bashrc
function proxy
{
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
}
function unproxy
{
unset http_proxy
unset https_proxy
}
使用时执行 proxy ,取消时执行 unproxy
参考
https://gist.github.com/laispace/666dd7b27e9116faece6
https://blog.csdn.net/omaidb/article/details/118104908
全文完。
如果转发本文,文末务必注明:“转自微信公众号:生有可恋”。
原文始发于微信公众号(生有可恋):github 客户端设置
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论