GIT设置HTTP代理

1. 下载 http://zwitterion.org/software/ssh-https-tunnel/ssh-https-tunnel到~/.ssh/ssh-https-tunnel

#!/usr/bin/perl -T -w
# Copyright (C) 2001,2002,2008 Mark Suter <[email protected]>
#
# This program tunnels a secure shell connection via a https proxy as
# the ProxyCommand program.  The destination secure shell server needs
# to be running on port 443 unless the proxy is very lenient.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: ssh-https-tunnel,v 2.8 2008/02/03 06:14:44 suter Exp suter $

use strict;
use IO::Select;
use IO::Socket;

################################
##  Start User Configuration  ##
################################

# Proxy details
my $host = "proxy.example.com";
my $port = 3128;

# Basic Proxy Authentication - leave empty if you don't need it
my $user = "";
my $pass = "";

# Add an entry to your ~/.ssh/config that so "ssh remote.example.org"
# uses this program to proxy the connection.
#
#    host remote.example.org
#        ProxyCommand /path/to/ssh-https-tunnel %h %p
#        Port 443
#        ServerAliveInterval 10
#
# The last option enables Keep Alives to avoid the problem of many
# proxies timing out inactive connections.  Check your ssh client's
# documentation for details.
#
# If you are behind a Microsoft ISA server, or similar proxy that uses
# NTLM, see http://www.google.com/search?q=ntlm+proxy+auth for ideas.

################################
##   End User Configuration   ##
################################

## Based on "MIME::Base64::old_encode_base64" to avoid that dependancy
sub auth_header($$) {
    my ( $user, $pass ) = @_;

    sub encode_base64 ($;$) {
        my $eol = $_[1];
        $eol = "\n" unless defined $eol;

        my $res = pack( "u", $_[0] );

        # Remove first character of each line, remove newlines
        $res =~ s/^.//mg;
        $res =~ s/\n//g;

        $res =~ tr|` -_|AA-Za-z0-9+/|;  # ` help syntax parsers

        # fix padding at the end
        my $padding = ( 3 - length( $_[0] ) % 3 ) % 3;
        $res =~ s/.{$padding}$/'=' x $padding/e if $padding;

        # break encoded string into lines of no more than 76 characters each
        if ( length $eol ) {
            $res =~ s/(.{1,76})/$1$eol/g;
        }
        return $res;
    }

    return "Proxy-Authorization: Basic " . encode_base64( "$user:$pass", "\015\012" );
}

## Tunnel the connection and return a handle for it
sub tunnel_connect($$$$$$) {
    my ( $host, $port, $user, $pass, $remote_host, $remote_port ) = @_;

    my $socket = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port )
        or die "$0: Can't connect to $host:$port: $!\n";

    $socket->print( "CONNECT $remote_host:$remote_port HTTP/1.0\015\012",
        $user ? auth_header( $user, $pass ) : "", "\015\012" )
        or die "$0: Can't write: $!\n";

    local $/ = "\012";
    my $response = $socket->getline() or die "$0: Can't read: $!\n";
    $response =~ /^HTTP\/... 2/i or die "$0: CONNECT failed: $response";
    do { $response = $socket->getline() or die "$0: Can't read: $!\n"; }
        until $response =~ /^\s+$/;

    return $socket;
}

## Move data from one handle to another
sub proxy_data($$) {
    my ( $source, $destination ) = @_;

    my ( $buffer, $length, $offset, $bytes ) = ( "", 0, 0, 0 );
    $length = sysread( $source, $buffer, 4096, $offset ) or return 0;
    while ($length) {
        $bytes = syswrite( $destination, $buffer, $length, $offset ) or return 0;
        $offset += $bytes;
        $length -= $bytes;
    }
    return 1;
}

## Check we have two arguments
defined $ARGV[0] and defined $ARGV[1] or die "Usage $0 <host> <port>\n";

## Setup the tunnel
my $proxy = tunnel_connect( $host, $port, $user, $pass, $ARGV[0], $ARGV[1] );

## Shift data around in each direction
my $sel = IO::Select->new( [ \*STDIN, $proxy ], [ $proxy, \*STDOUT ] );
SELECT: while ( my @ready = $sel->can_read() ) {
    foreach my $handle (@ready) {
        proxy_data( $$handle[0], $$handle[1] ) or last SELECT;
    }
}

2.
vi ~/.ssh/ssh-https-tunnel

设置代理IP,端口;

使用红杏公益:http://hx.gy:1080,支持github.com

################################
##  Start User Configuration  ##
################################

# Proxy details
my $host = "hx.gy";
my $port = 1080;

# Basic Proxy Authentication - leave empty if you don't need it
my $user = "";
my $pass = "";

3. vi ~/.ssh/config

Host github.com
ProxyCommand ~/.ssh/ssh-https-tunnel %h %p
Port 443
Hostname ssh.github.com

4. 添加rsa公钥到github

5. 测试

[email protected]:ckelsel/virtualbox.git

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-07-31 14:35:53

GIT设置HTTP代理的相关文章

git设置ss代理

// 查看当前代理设置 git config --global http.proxy http/https协议 //设置代理(clone https://前缀的repo会走代理) git config --global http.proxy 'http://127.0.0.1:1080' git config --global https.proxy 'http://127.0.0.1:1080' git config --global http.proxy 'socks5://127.0.0.

为git设置socket代理

最近想看看tensorflow的资料和源码,很不幸google一直是被墙的.使用socket代理,可以访问相关网页,如果是想通过git下载源码,也可以使用socket代理. git实际上使用的夜市curl,所以通过环境变量可以实现这一点: export all_proxy=socks5://127.0.0.1:10888 这样就可以用git访问那些被墙掉的code repository了

Git 设置 SOCKS 代理

$ export all_proxy=socks5://127.0.0.1:1080

linux 下 git gem 等代理设置问题

github.com,作为程序员的代码仓库,我们经常会用到.但有时候我们不能直接通过网络链接它,只能通过代理. 这里我有一台代理服务器,起初我以为在终端设置了代理环境就行了,其设置为在你的~/.bashrc里增加以下几行: [python] view plaincopy export http_proxy="http://proxy-server:3128/" export https_proxy="http://proxy-server:3128/" export

git设置、查看、取消代理

设置当前代理为 http://127.0.0.1:1080 或 socket5://127.0.0.1:1080: git config --global http.proxy 'http://127.0.0.1:1080' git config --global https.proxy 'http://127.0.0.1:1080' git config --global http.proxy 'socks5://127.0.0.1:1080' git config --global http

常用工具设置互联网代理

设置上网代理地址的格式为 [protocol]://[username]:[password]@[ip]:[port] linux 全局代理 编辑/etc/profile http_proxy=代理地址 export http_proxy linux yum 编辑/etc/yum.conf 添加变量 proxy=代理地址 git git config --global http.proxy http://yourname:[email protected]:proxyport

MacOS代理设置(桌面应用代理设置&amp;Terminal代理设置)

MacOS代理分为桌面应用代理设置&Terminal代理设置,使用代理软件默认只会开启桌面应用代理,Terminal代理需要单独配置 桌面应用代理设置 Terminal查看桌面应用代理设置情况 scutil --proxy 返回内容(0表示未开启,1表示已开启,ExceptionsList 表示无需代理的地址列表) <dictionary> { HTTPEnable : 0 HTTPSEnable : 0 ProxyAutoConfigEnable : 0 SOCKSEnable :

Android模拟器设置网络代理方法

在服务器上启动模拟器的时候加了--http-proxy,但是不起作用.所以搜了下面的方法 四种方法: 一:将网络连接代理设置写入配置数据库 (适合启动模拟器无界面) 1.通过命令行或者通过双击emulatoer可执行文件,打开模拟器 2.在命令行执行adb shell 打开android的控制台 (确保环境变量设置正确,即已经把Android_SDK/tools 添加到了PATH(Linux)/path(Windows)) 3.执行 ls -l /data/data/com.android.pr

设置HTTP代理

Maven通过<<UserHome>>/.m2/settings.xml(如果没有该文件,复制<<MavenHome>>/conf/settings.xml到<<UserHome>>/.m2/目录下)设置HTTP代理 <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.