github.com,作为程序员的代码仓库,我们经常会用到。但有时候我们不能直接通过网络链接它,只能通过代理。

这里我有一台代理服务器,起初我以为在终端设置了代理环境就行了,其设置为在你的~/.bashrc里增加以下几行:

  1. export http_proxy="http://proxy-server:3128/"
  2. export https_proxy="http://proxy-server:3128/"
  3. export ftp_proxy="http://proxy-server:3128/"

设置好以后,使用以下命令使其启动

  1. source ~/.bashrc

然后测试wget是没有问题的,如下:

但使用git clone就不行

  1. git clone git@github.com:aborn/ulitcs.git

通过这两篇文章知道了原因:在windows上通过代理访问github.com 和 Using git over proxy

配制过程分为以下几步:

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

  1. 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=proxy-server
  14. _proxyport=3128
  15. exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

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

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

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

  1. export PATH=$PATH:/home/lisp/local/bin
  1. source ~/.bashrc

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

  1. gitproxy = git-proxy

我.gitconfig文件内容如下:

  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

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

只要下载connect.c文件即可,然后编译

  1. gcc -o connect connect.c

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

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

  1. ProxyCommand /home/lisp/local/bin/connect -H proxy-server:3128 %h %p

我的~/.ssh/config文件内容如下:

  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

注意这里的connect文件目录与第5步放置的目录一致。

以上步骤完成后,就行了,如下截图:

  1. git clone git@github.com:aborn/ulitcs.git

  1. git push

注意:

1. 上面的proxy-server根据你的代理,设置为替换为你的代理服务器的ip地址或者域名

2. 上面的connect.c 文件、编译好的connect文件和git-proxy文件,也可以从这里下载connect.tar.gz 和git-proxy

3. 我的操作系统为Ubuntu 14.04LTS

linux 下 git gem 等代理设置问题的更多相关文章

  1. linux下git的安装和使用(转)

    转自:http://www.cnblogs.com/sunada2005/archive/2013/06/06/3121098.html 最近在使用github,感觉不错.在windows下,可使用g ...

  2. Linux下git安装配置

    一.Linux下git安装配置 2013-07-28 20:32:10|  分类: 默认分类 |  标签:linux  git  server  |举报|字号 订阅     http://abomby ...

  3. Linux下Git和GitHub使用方法总结

    来源:Linux下Git和GitHub使用方法总结 1 Linux下Git和GitHub环境的搭建 第一步: 安装Git,使用命令 “sudo apt-get install git” 第二步: 到G ...

  4. linux下git的简单运用

    linux下git的简单运用 windows下也有git,是git公司出的bash,基本上模拟了linux下命令行.许多常用的命令和linux下操作一样.也就是说,windows下的git命令操作和l ...

  5. linux下git使用记录1 git 提交

    linux下git使用记录1   浏览:985 发布日期:2013/08/08 分类:技术分享 在使用github的时候,不可避免的接触到了git,用他来更新项目,做版本控制.这里特别把常用的命令记录 ...

  6. hadoop搭建杂记:Linux下JDK环境变量的设置(三种配置环境变量的方法)

    Linux下JDK环境变量的设置(三种配置环境变量的方法) Linux下JDK环境变量的设置(三种配置环境变量的方法) ①修改/etc/profile文件 如果你的计算机仅仅作为开发使用时推荐使用这种 ...

  7. Linux Linux下最大文件描述符设置

    Linux下最大文件描述符设置 by:授客 QQ:1033553122 1.   系统可打开最大文件描述符设置 查看系统可打开最大文件描述符 # cat /proc/sys/fs/file-max 6 ...

  8. linux下为目录和文件设置权限

    摘:linux下为目录和文件设置权限 分类: Linux2012-05-09 03:18 7456人阅读 评论(1) 收藏 举报 linuxwordpressweb数据库serverfile linu ...

  9. Linux下网络服务的安全设置

    Linux下网络服务的安全设置      Linux操作系统由于其良好的稳定性.健壮性.高效性和安全性.正在成为各种网络服务的理想平台.各种网络应用在Linux系统上部有性能卓越的应用,例如,提供We ...

随机推荐

  1. u-boot 2016.05 添加u-boot cmd

    记录一下如何在u-boot 添加一个自己想要的命令. 首先来看一下宏,include/command.h 218 #define U_BOOT_CMD(_name, _maxargs, _rep, _ ...

  2. Quartz 与 Spring集成

    http://www.cnblogs.com/pigwing/archive/2011/07/12/2104002.html http://blog.arganzheng.me/posts/quart ...

  3. 百兆千兆网口100Base-TX/1000Base-T

    100Base-TX快速以太网目前制定的三种有关传输介质的标准之一. 另外两种是100Base-T4,100Base-FX. 100标识传输速率为100Mbit/s. base标识采用基带传输. T代 ...

  4. 标准Drupal7安装中文翻译出错解决办法

    这个问题在网上解决的方案一致都是说在\sites\default\settings.php文件,在最后增加以下两行: ini_set('memory_limit', '1280M'); //加大php ...

  5. 測试Service

    <strong><span style="font-size:18px;">自己定义Service:</span></strong> ...

  6. Web API(三):创建Web API项目

    在本篇文章中将讲解如何使用Visual Studio创建一个新的ASP.NET Web API项目. 在Visual Studio中有两种方式用于创建Web API项目: 1.创建带MVC的Web A ...

  7. PHP 获取图片中的器材信息

    function getExif($img){ $exif = exif_read_data($img, 'IFD0'); return array ( '文件名' => $exif['File ...

  8. r绘图基本

    R绘图命令分为三种类型: 高级绘图命令在图形设备上产生一个新的图区,它可能包括坐标轴,标签,标题等等. 低级画图命令会在一个已经存在的图上加上更多的图形元素,例如额外的点,线和标签. 交互式图形命令允 ...

  9. 【转】Microsoft .Net Remoting 之.Net Remoting基础篇

    .Net Remoting基础篇 一.Remoting基础 什么是Remoting,简而言之,我们可以将其看作是一种分布式处理方式.从微软的产品角度来看,可以说Remoting就是DCOM的一种升级, ...

  10. MongoDB 常用shell命令汇总

    //指定用户名和密码连接到指定的MongoDB数据库 mongo 192.168.1.200:27017/admin -u user -p password use youDbName 1.Mongo ...