Skip to content

Instantly share code, notes, and snippets.

@bynil
Last active January 23, 2024 12:37
Show Gist options
  • Star 54 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save bynil/2126e374db8495fe33de2cbc543149ae to your computer and use it in GitHub Desktop.
Save bynil/2126e374db8495fe33de2cbc543149ae to your computer and use it in GitHub Desktop.
Use git over socks5 proxy
Port: 1080
1. Create a file /YOUR PATH/gitproxy.sh with content:
#!/bin/sh
nc -X 5 -x 127.0.0.1:1080 "$@"
2. Edit your ~/.gitconfig
# For git://
[core]
gitproxy=/YOUR PATH/gitproxy.sh
# For http(s)://
[http]
proxy=socks5://127.0.0.1:1080
[https]
proxy=socks5://127.0.0.1:1080
3. Edit your /etc/ssh/ssh_config to change global setting (or ~/.ssh/config for special host)
# For ssh://
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
@sheepduke
Copy link

sheepduke commented Feb 11, 2020

I googled this post and want to add my 2 cents.

For Linux users

ProxyChains is also good solution. You may modify its configuration file and add your SOCKS server.

Then, simply type proxychains -q git clone git@xxx and the traffic goes through your proxy.

For Windows users

You may consider to use NMAP instead of NetCat, since you can barely find a trustful nc binary for Windows.

For Windows MSYS2 users

  1. Install socat package.
  2. Use the following proxy command ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=1070

@diamondburned
Copy link

Here's a short way to do this:

export GIT_SSH_COMMAND='ssh -o ProxyCommand="nc -X 5 -x 127.0.0.1:1080 %h %p"'
git ...

@sheepduke
Copy link

sheepduke commented Mar 11, 2020

I ended up with adding SSH proxy command in ~/.ssh/config.

I found it rather convenient since it works for both Linux and Windows:

Host github.com
  ProxyCommand connect -H 127.0.0.1:1070 %h %p

You just need Privoxy that transforms a SOCKS proxy into HTTP proxy. I made it listen on port 1070.

It will always use the 1070 HTTP proxy to establish SSH connection.

@bynil
Copy link
Author

bynil commented Mar 11, 2020

I ended up with adding SSH proxy command in ~/.ssh/config.

I found it rather convenient since it works for both Linux and Windows:

Host github.com
  ProxyCommand connect -H 127.0.0.1:1070 %h %p

You just need Privoxy that transforms a SOCKS proxy into HTTP proxy. I made it listen on port 1070.

It will always use the 1070 HTTP proxy to establish SSH connection.

Yes, once for all.

My config over socks5 proxy:

Host github.com
	HostName github.com
	User git
	IdentityFile ~/.ssh/github-ssh.key
	ProxyCommand /usr/bin/nc -X 5 -x 127.0.0.1:6153 %h %p

@nghinv
Copy link

nghinv commented Apr 9, 2020

Nice!

@jkeridLNX3
Copy link

error appear /
Have already downloaded socks5 list as socks5.txt

Socks5 Proxy file path(socks5.txt):

@yuanalexwu
Copy link

yuanalexwu commented Sep 1, 2021

Here's a short way to do this:

export GIT_SSH_COMMAND='ssh -o ProxyCommand="nc -X 5 -x 127.0.0.1:1080 %h %p"'
git ...

It works!

@pessimo
Copy link

pessimo commented Jan 9, 2022

sorry to ask question here. But, what's the point of setting ssh config with proxycommand when you already create a proxy with nc?

@sheepduke
Copy link

sorry to ask question here. But, what's the point of setting ssh config with proxycommand when you already create a proxy with nc?

When you use nc or connect command, a tunnel is established to proxy the network traffic. But without setting ProxyCommand, SSH is not aware of this tunnel. You have to explicitly tell it to use this tunnel for data transmission.

@finalcreator
Copy link

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