Skip to content

Instantly share code, notes, and snippets.

@yougg
Last active January 18, 2026 10:28
Show Gist options
  • Select an option

  • Save yougg/5d2b3353fc5e197a0917aae0b3287d64 to your computer and use it in GitHub Desktop.

Select an option

Save yougg/5d2b3353fc5e197a0917aae0b3287d64 to your computer and use it in GitHub Desktop.
complete ways to set http/socks/ssh proxy environment variables

set http or socks proxy

# set http proxy
export http_proxy=http://127.0.0.1:8080
# set socks proxy (local DNS)
export http_proxy=socks5://127.0.0.1:1080
# set socks proxy (remote DNS)
export http_proxy=socks5h://127.0.0.1:1080
export https_proxy=$http_proxy \
ftp_proxy=$http_proxy \
rsync_proxy=$http_proxy \
all_proxy=$http_proxy

export no_proxy="127.0.0.1,localhost,localaddress,.localdomain.com"

export HTTP_PROXY=$http_proxy \
HTTPS_PROXY=$http_proxy \
FTP_PROXY=$http_proxy \ 
RSYNC_PROXY=$http_proxy \
ALL_PROXY=$http_proxy \
NO_PROXY=$no_proxy

# set git http(s) proxy
git config --global http.sslverify false
git config --global http.proxy $http_proxy
git config --global https.proxy $http_proxy

# only for 'github.com'
git config --global http.https://github.com.proxy $http_proxy

set ssh proxy

# use 'nc' with http protocol
export ssh_proxy='ProxyCommand=nc -X connect -x PROXYHOST:PROXYPORT %h %p'
# use 'nc' with socks5 protocol
export ssh_proxy='ProxyCommand=nc -X 5 -x PROXYHOST:PROXYPORT %h %p'

# use 'connect' with http protocol
export ssh_proxy='ProxyCommand=connect -H PROXYHOST:PROXYPORT %h %p'
# use 'connect' with socks5 protocol
export ssh_proxy='ProxyCommand=connect -S PROXYHOST:PROXYPORT %h %p'

# connect to ssh server over proxy
ssh -o $ssh_proxy USER@FINAL_DEST

unset proxy

unset http_proxy https_proxy ftp_proxy rsync_proxy all_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY RSYNC_PROXY ALL_PROXY

git config --global --unset http.proxy
git config --global --unset https.proxy

git config --global --unset http.https://github.com.proxy

unset ssh_proxy
@4piu
Copy link
Copy Markdown

4piu commented Mar 3, 2021

A remind:

  • /etc/environment is not a script. It only supports KEY=VALUE syntax ($variable is not supported either)
  • /etc/profile does not support export {HTTP,HTTPS,FTP,RSYNC,ALL}_PROXY=$http_proxy, it may hang your login

@InsOpDe
Copy link
Copy Markdown

InsOpDe commented Apr 27, 2021

it needs to be git config --global core.sshCommand "ssh -o '$ssh_proxy'" because gitconfig ignores double quotation marks

@accdias
Copy link
Copy Markdown

accdias commented Oct 6, 2022

What is the syntax to use a socket file instead of IP:PORT as my proxy?

@SupinePandora43
Copy link
Copy Markdown

Socks5 proxy is: SOCKS_VERSION=5 SOCKS_SERVER=socks5://127.0.0.1:2080

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