Post

How to set proxy for ssh and git in Linux

A big problem of living in Iran is censorship

Long story short… Lets start with the easier one

proxy settings for git

These is two ways to do it

set a proxy globally (for every git request)

1
2
git config --global http.proxy http://<username>:<password>@<proxy.server.com>:<8080>
git config --global https.proxy http://<username>:<password>@<proxy.server.com>:<8080>

Set a proxy for specific Repository (aka. locally cloned repository)

  • Go to locally cloned repository folder
1
2
git config http.proxy http://<username>:<password>@<proxy.server.com>:<8080>
git config https.proxy http://<username>:<password>@<proxy.server.com>:<8080>

These two commands will add following lines to <REPO>/.git/config file

1
2
3
4
[http]
        proxy = http://127.0.0.1:2888
[https]
        proxy = http://127.0.0.1:2888

To verify your settings

1
2
git config --global --get http.proxy
git config --global --get https.proxy

πŸ“Œ Remove --global to check local repo

To Unset these proxies

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

πŸ“Œ Remove --global to remove local repo proxy

Set proxy for ssh

These section is somehow tricky

πŸ’‘ Install openbsd branch of netcat

β†’ In Arch linux, the proper package is openbsd-netcat , I read that there are two different packages for MacOS, You have to find proper package in any distro yourself

add following code toΒ ~/.ssh/config

1
2
3
4
Host github.com
        ProxyCommand    nc -x 127.0.0.1:2888 -X 5 %h %p
        User git
        Port 22
This post is licensed under CC BY 4.0 by the author.