Using a proxy under UbuntuLinux to use github.com on git

Source: Internet
Author: User
Tags using git
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

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?
  1. Export http_proxy = "http: // proxy-server: 3128 /"
  2. Export https_proxy = "http: // proxy-server: 3128 /"
  3. 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?
  1. 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?
  1. 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?
  1. 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?
  1. #! /Bin/sh
  2. # Use socat to proxy git through an http connect firewall.
  3. # Useful if you are trying to clone git: // from inside a company.
  4. # Requires that the proxy allows CONNECT to port 9418.
  5. #
  6. # Save this file as gitproxy somewhere in your path
  7. # (E.g .,~ /Bin) and then run
  8. # Chmod + x git-proxy
  9. # Git config -- global core. gitproxy git-proxy
  10. #
  11. #
  12. # Configuration. Common proxy ports are 3128,812 3, 8000.
  13. _ Proxy = proxy-server
  14. _ Proxyport = 3128
  15. 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?
  1. 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?
  1. Export PATH = $ PATH:/home/lisp/local/bin
export PATH=$PATH:/home/lisp/local/bin

[Python]View plaincopyprint?
  1. Source ~ /. Bashrc
source ~/.bashrc

 

 

4. modify ~ /. Gitconfig, add the following lines and proxies

 

[Python]View plaincopyprint?
  1. Gitproxy = git-proxy
gitproxy = git-proxy
The content of my. gitconfig file is as follows:

 

 

[Python]View plaincopyprint?
  1. [Push]
  2. Default = simple
  3. [User]
  4. Name = aborn
  5. Email = loveaborn@foxmail.com
  6. [Core]
  7. Editor = emacs
  8. Gitproxy = git-proxy
  9. [Https]
  10. Proxy = http: // proxy-server: 3128
  11. [Http]
  12. 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?
  1. 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?
  1. 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?
  1. ProxyCommand/home/lisp/local/bin/connect-H proxy-server: 3128% h % p
  2. Host github.com
  3. User loveaborn@foxmail.com
  4. Port 443
  5. 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?
  1. Git clone git@github.com: aborn/ulitcs. git
git clone git@github.com:aborn/ulitcs.git   

 

 

[Python]View plaincopyprint?
  1. Git push
git push


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.