当前位置:   article > 正文

Ubuntu Linux下通过代理(proxy)使用git上github.com_ubuntu如何设置代理去github下载

ubuntu如何设置代理去github下载

配制过程分为以下几步:

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


  1. sudo apt-get install socat  
sudo apt-get install socat

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

  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  
  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

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

  1. cp git-proxy /home/wilsonke/local/bin/  
cp git-proxy /home/wilsonke/local/bin/

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

  1. export PATH=$PATH:/home/wilsonke/local/bin  
export PATH=$PATH:/home/wilsonke/local/bin

  1. source ~/.bashrc  
source ~/.bashrc

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

  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:password@172.26.100.238:64000  
  11. [http]  
  12.     proxy = http://wilson_ke:password@172.26.100.238:64000  
  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:password@172.26.100.238:64000
  11. [http]
  12. proxy = http://wilson_ke:password@172.26.100.238:64000

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

  1. gcc -o connect connect.c  
gcc -o connect connect.c

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


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

  1. ProxyCommand /home/wilsonke/local/bin/connect -H 172.26.100.238:64000 %h %p  
  2. Host github.com  
  3. User 275156430@qq.com  
  4. Port 443  
  5. Hostname ssh.github.com  
  1. ProxyCommand /home/wilsonke/local/bin/connect -H 172.26.100.238:64000 %h %p
  2. Host github.com
  3. User 275156430@qq.com
  4. Port 443
  5. Hostname ssh.github.com

7.完成并测试

  1. git clone https://github.com/facebook/wangle  
git clone https://github.com/facebook/wangle

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


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


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

  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  
  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

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


参考资料

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/656913
推荐阅读
相关标签
  

闽ICP备14008679号