Ubuntu Linux下通过代理(proxy)使用git上github.com

配制过程分为以下几步:

1. 安装socat,在ubuntu下使用以下命令安装


[html] view plain copy
print ?
  1. sudo apt-get install socat  
sudo apt-get install socat

2. 编辑一个脚本文件,名字为git-proxy ,内容如下

[html] view plain copy
print ?
  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, 8123, 8000.  
  13. _proxy= 172.26.100.238  
  14. _proxyport=64000  
  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= 172.26.100.238
_proxyport=64000
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

 3. 将git-proxy放到一个目录下,如我将它放到/home/wilsonke/local/bin,并将该目录加入到PATH

[html] view plain copy
print ?
  1. cp git-proxy /home/wilsonke/local/bin/  
cp git-proxy /home/wilsonke/local/bin/

将该目录加入到PATH,加入以下内容到~/.bashrc,然后souce ~/.bashrc

[html] view plain copy
print ?
  1. export PATH=$PATH:/home/wilsonke/local/bin  
export PATH=$PATH:/home/wilsonke/local/bin

[html] view plain copy
print ?
  1. source ~/.bashrc  
source ~/.bashrc

4. 修改~/.gitconfig,加入以下行和代理

[html] view plain copy
print ?
  1. [push]  
  2.     default = simple  
  3. [user]  
  4.     name = wilsonke77  
  5.     email = 275156430@qq.com  
  6. [core]  
  7.     editor = emacs  
  8.     gitproxy = git-proxy  
  9. [https]  
  10.     proxy = http://wilson_ke:[email protected]:64000  
  11. [http]  
  12.     proxy = http://wilson_ke:[email protected]:64000  
[push]
	default = simple
[user]
	name = wilsonke77
	email = [email protected]
[core]
	editor = emacs
	gitproxy = git-proxy
[https]
	proxy = http://wilson_ke:[email protected]:64000
[http]
	proxy = http://wilson_ke:[email protected]:64000

5. 下载转换协议文件connect.c,下载地址 点击

[html] view plain copy
print ?
  1. gcc -o connect connect.c  
gcc -o connect connect.c

将编译后的文件connect也拷贝到/home/wilsonke/local/bin下


6. 修改~/.ssh/config,加入以下行

[html] view plain copy
print ?
  1. ProxyCommand /home/wilsonke/local/bin/connect -H 172.26.100.238:64000 %h %p  
  2. Host github.com  
  3. User [email protected]  
  4. Port 443  
  5. Hostname ssh.github.com  
ProxyCommand /home/wilsonke/local/bin/connect -H 172.26.100.238:64000 %h %p
Host github.com
User [email protected]
Port 443
Hostname ssh.github.com

7.完成并测试

[html] view plain copy
print ?
  1. git clone https://github.com/facebook/wangle  
git clone https://github.com/facebook/wangle

如果能正常clone下来,则表示成功。


后记:很多开源项目同时可能还会用到wget来下载代码,同样,wget也要设置代理服务器


创建用户的~/.wgetrc文件中,添加如下内容:

[html] view plain copy
print ?
  1. http_proxy = http://172.26.100.238:64000/  
  2. ftp_proxy = http://172.26.100.238:64000/  
  3. --proxy-user=wilson_ke  
  4. --proxy-passwd=password  
http_proxy = http://172.26.100.238:64000/
ftp_proxy = http://172.26.100.238:64000/
--proxy-user=wilson_ke
--proxy-passwd=password

完成了上述配置后,就可以成功编译facebook的项目proxygen


参考资料

http://blog.csdn.net/loveaborn/article/details/24575659

你可能感兴趣的:(Ubuntu Linux下通过代理(proxy)使用git上github.com)