How to force Git to use socks proxy over its ssh connection?
After some visiting so many pages, I finally find the solution to my question:
# [step 1] create a ssh-proxy
ssh -D 9999 -qCN user@server.net
# [step 2] make git connect through the ssh-proxy
# [current script only]
export GIT_SSH_COMMAND='ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [git global setting]
git config --global core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [one-time only use]
git clone -c=core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"' git@github.com:user/repo.git
# OR [current repository use only]
git config core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
To install connect
on Ubuntu:
sudo apt install connect-proxy
Getting Git to work with a proxy server - fails with Request timed out
Command to use:
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
- change
proxyuser
to your proxy user - change
proxypwd
to your proxy password - change
proxy.server.com
to the URL of your proxy server - change
8080
to the proxy port configured on your proxy server
Note that this works for both http and https repos.
If you decide at any time to reset this proxy and work without proxy:
Command to use:
git config --global --unset http.proxy
Finally, to check the currently set proxy:
git config --global --get http.proxy
Only use a proxy for certain git urls/domains?
I usually use the environment variables:
http_proxy=http://username:password@proxydomain:port
https_proxy=http://username:password@proxydomain:port
That is picked up by git when accessing GitHub repo.
Note:
- both
http_proxy
andhttps_proxy
must use thehttp://
url of the proxy (nohttps://
). - always use the fqn (full qualified name) of
proxydomain
(don't rely on its short name)
But for internal repo, all I have to do is define and export one more environment variable:
no_proxy=.my.company,localhost,127.0.0.1,::1
, for accessing any repo with an address likemyrepo.my.company
or localhost.
You can define NO_PROXY
or no_proxy
, it doesn't matter.
But just in case, I always set HTTP_PROXY
, HTTPS_PROXY
, http_proxy
, https_proxy
, NO_PROXY
and no_proxy
.
Related Topics
Shell Script Get Ctrl+Z with Trap
Does Cron Expression in Unix/Linux Allow Specifying Exact Start and End Dates
How to See Contents of Hive Orc Files in Linux
Hadoop: Require Root's Password After Enter "Start-All.Sh"
Branch-Specific Configuration File Maintenance with Git
Find Out If File Has Been Modified Within the Last 2 Minutes
Is It Ok (Performance-Wise) to Have Hundreds or Thousands of Files in the Same Linux Directory
How to Run the Cron Job as a User Instead of Root User
Component Based Web Project Directory Layout with Git and Symlinks
On X64 Linux, Differencebetween Syscall, Int 0X80 and Ret to Exit a Program
Compiling 32 Bit Assembler on 64 Bit Ubuntu
How to Set Environment Variables on Ec2 Instance via User Data
Where Are Ioctl Parameters (Such as 0X1268/Blksszget) Actually Specified
How to Execve a Process, Retaining Capabilities in Spite of Missing Filesystem-Based Capabilities