Skip to content

Instantly share code, notes, and snippets.

@chenshengzhi
Last active November 8, 2024 08:31
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://git.521000.best.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
@Iridescent-zhang
Copy link

经过不断的尝试,我找到找到了属于我的正确配置方法

Host github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\Users\用户名\.ssh\id_rsa"
  TCPKeepAlive yes
  ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\Users\用户名\.ssh\id_rsa"
  TCPKeepAlive yes
  ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p

使用 ssh 命令测试没问题,实际使用也正常了

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

我一开始使用 Host github.com User git Hostname github.com IdentityFile "C:\Users\用户名.ssh\id_rsa" ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p 这个配置,期间还更换S为H,或者更换端口号7890到7891,都不成功,就很奇怪,不知道哪里的问题

就是得把 github.com 设置成走ssh.github.com和443端口才行,应该是后来才改的

感觉关键不是ssh.github.com,而是443

@UshioA
Copy link

UshioA commented Apr 13, 2024

为gitlab配置类似的代理:

Host gitlab.com
	User git
	Port 443
	Hostname altssh.gitlab.com
	IdentityFile ~/.ssh/id_ed25519
	IdentitiesOnly yes
	ProxyCommand nc -X connect -x localhost:1080 %h %p

@luoyinong
Copy link

经过不断的尝试,我找到找到了属于我的正确配置方法

Host github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\Users\用户名\.ssh\id_rsa"
  TCPKeepAlive yes
  ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\Users\用户名\.ssh\id_rsa"
  TCPKeepAlive yes
  ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p

使用 ssh 命令测试没问题,实际使用也正常了

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

我一开始使用 Host github.com User git Hostname github.com IdentityFile "C:\Users\用户名.ssh\id_rsa" ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p 这个配置,期间还更换S为H,或者更换端口号7890到7891,都不成功,就很奇怪,不知道哪里的问题

这个有用, 之前一直报
CreateProcessW failed error:2
posix_spawnp: No such file or directory

@evan4C
Copy link

evan4C commented Jul 22, 2024

mac 配合clashX的7890 socks5配置:

Host github.com Hostname ssh.github.com Port 443 User git ProxyCommand nc -v -x 127.0.0.1:7890 %h %p

这个方法对我有用,感谢

@WenHv587
Copy link

经过不断的尝试,我找到找到了属于我的正确配置方法

Host github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\Users\用户名\.ssh\id_rsa"
  TCPKeepAlive yes
  ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\Users\用户名\.ssh\id_rsa"
  TCPKeepAlive yes
  ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p

使用 ssh 命令测试没问题,实际使用也正常了

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

这个对我有用。Windows10

@jon9527
Copy link

jon9527 commented Jul 31, 2024

ssh over https提到域名改成ssh.github.com了

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

感谢,非常有用。

确实有用,mac+clash+tun模式成功测试。谢谢

@suyanhj
Copy link

suyanhj commented Oct 8, 2024

ssh -T [email protected]

好用

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