Skip to content

Instantly share code, notes, and snippets.

@chenshengzhi
Last active August 29, 2025 05:35
Show Gist options
  • Save chenshengzhi/07e5177b1d97587d5ca0acc0487ad677 to your computer and use it in GitHub Desktop.
Save chenshengzhi/07e5177b1d97587d5ca0acc0487ad677 to your computer and use it in GitHub Desktop.
git ssh 代理设置

仅为 GitHub 设置代理

git 代理

设置 git config --global http.https://github.com.proxy socks5://127.0.0.1:1086
设置完成后, ~/.gitconfig 文件中会增加以下条目:

[http "https://github.com"]
    proxy = socks5://127.0.0.1:1086
ssh 代理

修改 ~/.ssh/config 文件

Host github.com
    User git
    ProxyCommand nc -v -x 127.0.0.1:1086 %h %p
@vcheckzen
Copy link

在 Windows 下使用 ProxyCommand connect 设置现在 Powershell 中用 ssh 连接 git 失效,pull 和 push 都失败,命令

ssh -T git@github.com

返回错误:

CreateProcessW failed error:2
posix_spawnp: No such file or directory

但是使用 git bash 进行连接却是正常的,请问这是什么原因呢?以前这个设置在 Powershell 中也能用

如果 gitsh 命令在系统 PATH 里,通过下面的命令检测

PS > scoop which sh
~\scoop\apps\git\current\bin\sh.exe

PS > sh -l -c "which connect"
/mingw64/bin/connect

那么下面的配置在 Git BashPowerShell 里都可以工作

Host github.com
  HostName 	      ssh.github.com
  Port            443
  User            git
  IdentityFile    ~/.ssh/pri_gh
  # -H HTTP_PROXY, -S SOCK5_PROXY
  ProxyCommand    sh -c "connect -H 127.0.0.1:10802 %h %p"

Git Bash

$ ssh -T github.com
Hi <name>! You've successfully authenticated, but GitHub does not provide shell access.

$ ssh -T [email protected]
Hi <name>! You've successfully authenticated, but GitHub does not provide shell access.

PowerShell

> ssh -T github.com
Hi <name>! You've successfully authenticated, but GitHub does not provide shell access.

> ssh -T [email protected]
Hi <name>! You've successfully authenticated, but GitHub does not provide shell access.

@vrqq
Copy link

vrqq commented Aug 29, 2025

补充Redhat 9环境下socks4代理用法 (使用V2RayA)

Host github.com
    User git
    ProxyCommand nc --proxy-type socks4 --proxy 127.0.0.1:20170 %h %p

检验

[vrqq@apm3 ~]$ ssh [email protected]
PTY allocation request failed on channel 0
Hi vrqq! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

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