如果在公司内通过代理上网或者因为某些已知的非可抗力因素导致我们上网必须通过代理,用本地客户端访问github时,如果不做配置的话通过ssh来克隆repository的时候,用原生命令是不能直接访问的,需要配置下代理。
方法1. 配置ssh的配置文件
#回归家目录
thinker@thinker-young MINGW64 ~/.ssh
$ cd
# 查看家目录在windows中的位置
thinker@thinker-young MINGW64 ~
$ pwd
/c/Users/thinker
#切到ssh的配置文件下
thinker@thinker-young MINGW64 ~
$ cd .ssh
# 创建配置文件
thinker@thinker-young MINGW64 ~/.ssh
$ vi config
#写入下面的内容
#其中 10.80.22.24是代理服务器的地址,80是端口
thinker@thinker-young MINGW64 ~/.ssh
$ cat config
Host github.com
ProxyCommand connect -H 10.80.22.42:80 %h %p
#ProxyCommand ~/.ssh/ssh-https-tunnel %h %p
Port 443
Hostname ssh.github.com
#保存退出
thinker@thinker-young MINGW64 ~/.ssh
方法2.如果代理需要密码访问,可以用下面的方法
下载一个脚本放到.ssh目录下,命名为ssh-https-tunnel
下载地址:https://zwitterion.org/software/ssh-https-tunnel/ssh-https-tunnel
2.1 配置ssh的配置文件
#回归家目录
thinker@thinker-young MINGW64 ~/.ssh
$ cd
# 查看家目录在windows中的位置
thinker@thinker-young MINGW64 ~
$ pwd
/c/Users/thinker
#切到ssh的配置文件下
thinker@thinker-young MINGW64 ~
$ cd .ssh
# 创建配置文件
thinker@thinker-young MINGW64 ~/.ssh
$ vi config
#写入下面的内容
thinker@thinker-young MINGW64 ~/.ssh
$ cat config
Host github.com
ProxyCommand ~/.ssh/ssh-https-tunnel %h %p
Port 443
Hostname ssh.github.com
#保存退出
thinker@thinker-young MINGW64 ~/.ssh
2.2 配置代理服务器和密码
打开刚才下载ssh-https-tunnel这个文件,完成代理服务器ip和端口,及用户名和密码的配置:
################################
## Start User Configuration ##
################################
# Proxy details
my $host = "10.80.22.44";
my $port = 80;
# Basic Proxy Authentication - leave empty if you don't need it
my $user = "username";
my $pass = "userpass";
# 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 ##
################################
如果是用的微软的NTLM认真的代理的话可以参考这位道友的文章:
http://blog.csdn.net/bluishglc/article/details/37600773