Github.com is often used as a programmer's code repository. But sometimes we cannot directly connect to it through the network, but only through the proxy.
Here I have a proxy server. At first I thought it was enough to set up the proxy environment on the terminal ~ /. Add the following lines to bashrc:
[Python]View plaincopyprint?
- Export http_proxy = "http: // proxy-server: 3128 /"
- Export https_proxy = "http: // proxy-server: 3128 /"
- Export ftp_proxy = "http: // proxy-server: 3128 /"
export http_proxy="http://proxy-server:3128/"export https_proxy="http://proxy-server:3128/"export ftp_proxy="http://proxy-server:3128/"
After setting, run the following command to start
[Python]View plaincopyprint?
- Source ~ /. Bashrc
source ~/.bashrc
Then, the wget test is correct, as shown below:
But it won't work if you use git clone.
[Python]View plaincopyprint?
- Git clone git@github.com: aborn/ulitcs. git
git clone git@github.com:aborn/ulitcs.git
These two articles show the cause: Access github.com and Using git over proxy through proxy on windows
The preparation process is divided into the following steps:
1. Install socat. Run the following command in ubuntu to install socat:
[Python]View plaincopyprint?
- Sudo apt-get install socat
sudo apt-get install socat
2. edit a script file named git-proxy. The content is as follows:
[Python]View plaincopyprint?
- #! /Bin/sh
- # Use socat to proxy git through an http connect firewall.
- # Useful if you are trying to clone git: // from inside a company.
- # Requires that the proxy allows CONNECT to port 9418.
- #
- # Save this file as gitproxy somewhere in your path
- # (E.g .,~ /Bin) and then run
- # Chmod + x git-proxy
- # Git config -- global core. gitproxy git-proxy
- #
- #
- # Configuration. Common proxy ports are 3128,812 3, 8000.
- _ Proxy = proxy-server
- _ Proxyport = 3128
- Exec socat stdio proxy: $ _ proxy: $1: $2, proxyport = $ _ proxyport
#!/bin/sh# Use socat to proxy git through an HTTP CONNECT firewall.# Useful if you are trying to clone git:// from inside a company.# Requires that the proxy allows CONNECT to port 9418.## Save this file as gitproxy somewhere in your path# (e.g., ~/bin) and then run# chmod +x git-proxy# git config --global core.gitproxy git-proxy### Configuration. Common proxy ports are 3128, 8123, 8000._proxy=proxy-server_proxyport=3128exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport
3. Put git-proxy in a directory, such as/home/lisp/local/bin, and add the directory to PATH.
[Python]View plaincopyprint?
- Cp git-proxy/home/lisp/local/bin/
cp git-proxy /home/lisp/local/bin/
Add the directory to PATH and add the following content ~ /. Bashrc, and then souce ~ /. Bashrc
[Python]View plaincopyprint?
- Export PATH = $ PATH:/home/lisp/local/bin
export PATH=$PATH:/home/lisp/local/bin
[Python]View plaincopyprint?
- Source ~ /. Bashrc
source ~/.bashrc
4. Modify ~ /. Gitconfig, add the following lines and Proxies
[Python]View plaincopyprint?
- Gitproxy = git-proxy
gitproxy = git-proxy
The content of my. gitconfig file is as follows:
[Python]View plaincopyprint?
- [Push]
- Default = simple
- [User]
- Name = aborn
- Email = loveaborn@foxmail.com
- [Core]
- Editor = emacs
- Gitproxy = git-proxy
- [Https]
- Proxy = http: // proxy-server: 3128
- [Http]
- Proxy = http: // proxy-server: 3128
[push]default = simple[user]name = abornemail = loveaborn@foxmail.com[core]editor = emacsgitproxy = git-proxy[https]proxy = http://proxy-server:3128[http]proxy = http://proxy-server:3128
5. Download the conversion protocol File connect. c and click
Download the connect. c file and compile
[Python]View plaincopyprint?
- Gcc-o connect. c
gcc -o connect connect.c
Copy the compiled File connect to/home/lisp/local/bin.
6. Modify ~ /. Ssh/config, add the following lines
[Python]View plaincopyprint?
- ProxyCommand/home/lisp/local/bin/connect-H proxy-server: 3128% h % p
ProxyCommand /home/lisp/local/bin/connect -H proxy-server:3128 %h %p
My ~ The content of the/. ssh/config file is as follows:
[Python]View plaincopyprint?
- ProxyCommand/home/lisp/local/bin/connect-H proxy-server: 3128% h % p
- Host github.com
- User loveaborn@foxmail.com
- Port 443
- Hostname ssh.github.com
ProxyCommand /home/lisp/local/bin/connect -H proxy-server:3128 %h %pHost github.comUser loveaborn@foxmail.comPort 443Hostname ssh.github.com
Note that the connect file directory here is the same as the directory placed in step 1.
After the preceding steps are completed, you can:
[Python]View plaincopyprint?
- Git clone git@github.com: aborn/ulitcs. git
git clone git@github.com:aborn/ulitcs.git
[Python]View plaincopyprint?
- Git push
git push