版權聲明:本文為博主原創文章,未經博主同意不得轉載。 https://blog.csdn.net/loveaborn/article/details/24575659
github.com。作為程序猿的代碼倉庫。我們常常會用到。
但有時候我們不能直接通過網絡鏈接它,僅僅能通過代理。
這里我有一台代理服務器,起初我以為在終端設置了代理環境即可了,其設置為在你的~/.bashrc里增加下面幾行:
export http_proxy="http://proxy-server:3128/"
export https_proxy="http://proxy-server:3128/"
export ftp_proxy="http://proxy-server:3128/"
設置好以后。使用下面命令使其啟動
source ~/.bashrc
然后測試wget是沒有問題的。例如以下:
但使用git clone就不行
git clone git@github.com:aborn/ulitcs.git
通過這兩篇文章知道了原因:
在windows上通過代理訪問github.com 和
Using git over proxy
配制過程分為下面幾步:
1. 安裝socat,在ubuntu下使用下面命令安裝
sudo apt-get install socat
2. 編輯一個腳本文件。名字為git-proxy 。內容例如以下
#!/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=3128
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport
3. 將git-proxy放到一個文件夾下。如我將它放到/home/lisp/local/bin,並將該文件夾增加到PATH
cp git-proxy /home/lisp/local/bin/
將該文件夾增加到PATH,增加下面內容到~/.bashrc。然后souce ~/.bashrc
export PATH=$PATH:/home/lisp/local/bin
source ~/.bashrc
gitproxy = git-proxy
我.gitconfig文件內容例如以下:
[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
5. 下載轉換協議文件connect.c,下載地址點擊
僅僅要下載connect.c文件即可,然后編譯
gcc -o connect connect.c
將編譯后的文件connect也復制到/home/lisp/local/bin下
6. 改動~/.ssh/config,增加下面行
ProxyCommand /home/lisp/local/bin/connect -H proxy-server:3128 %h %p
我的~/.ssh/config文件內容例如以下:
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
注意這里的connect文件文件夾與第5步放置的文件夾一致。
以上步驟完畢后。即可了,例如以下截圖:
git clone git@github.com:aborn/ulitcs.git
git push

注意:
1. 上面的proxy-server依據你的代理,設置為替換為你的代理服務器的ip地址或者域名
2. 上面的connect.c 文件、編譯好的connect文件和git-proxy文件,也能夠從這里下載connect.tar.gz 和 git-proxy
3. 我的操作系統為Ubuntu 14.04LTS