Last active
January 12, 2025 18:47
-
-
Save laispace/666dd7b27e9116faece6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git config --global https.proxy http://127.0.0.1:1080 | |
git config --global https.proxy https://127.0.0.1:1080 | |
git config --global --unset http.proxy | |
git config --global --unset https.proxy | |
npm config delete proxy |
结合以上各位经验设置成功. 以下以macOS为准.
https访问
仅为github.com设置socks5代理(推荐这种方式, 公司内网就不用设代理了, 多此一举):
git config --global http.https://github.com.proxy socks5://127.0.0.1:1086
其中1086是socks5的监听端口, 这个可以配置的, 每个人不同, 在macOS上一般为1086.
设置完成后, ~/.gitconfig文件中会增加以下条目:[http "https://github.com"] proxy = socks5://127.0.0.1:1086
ssh访问
需要修改~/.ssh/config文件, 没有的话新建一个. 同样仅为github.com设置代理:Host github.com User git ProxyCommand nc -v -x 127.0.0.1:1086 %h %p
如果是在Windows下, 则需要个性%home%.ssh\config, 其中内容类似于:
Host github.com User git ProxyCommand connect -S 127.0.0.1:1086 %h %p
这里-S表示使用socks5代理, 如果是http代理则为-H. connect工具git自带, 在\mingw64\bin\下面.
worked.
亲测可以,我的代理是Clash,端口改成默认的7890.
记录下问题过程: Clash 一开始使用Git命令没问题,突然某天提示:ssh: connect to host ssh.github.com port 22: Connection refused fatal: Could not read from remote repository.
win10配置:.ssh/config 配置文件供参考:
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
亲测可以,困扰一天了~感谢
确实有效!感谢
thanks a lot!
实测如下, 详细见: https://gist.github.com/liuyunbin/b6b820ecca264e2768e6574dc4235763#git
# 1. http 协议
git config --global http.proxy http://192.168.68.1:7890; # 设置 http 代理
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置
git config --global http.proxy socks5h://192.168.68.1:7890; # 设置 socks5h 代理
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置
# 2. ssh 协议访问
# 2.1 windows 10 --- git-bash
在 ~/.ssh/config 中添加: --- http 代理
Host github.com
ProxyCommand connect -H 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks 代理
Host github.com
ProxyCommand connect -S 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
# 2.2 centos 7
在 ~/.ssh/config 中添加: --- http 代理
Host github.com
ProxyCommand nc --proxy-type http --proxy 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks5 代理
Host github.com
ProxyCommand nc --proxy-type socks5 --proxy 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
# 2.3 ubuntu 24.04
在 ~/.ssh/config 中添加: --- http 代理
Host github.com
ProxyCommand nc -X connect -x 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks5 代理
Host github.com
ProxyCommand nc -X 5 -x 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
救命了,谢谢。对于解决【v2rayA开启透明代理后ssh连不上】有效