使用git协议-通过socks5代理加速对github的访问

作者

github访问不流畅,影响工作效率。这里总结下如何通过 socks 代理加速对github 的访问 。这使用 git 协议 ,因为使用 git协议可以看到网速,并且提交也很方便。 https协议似乎看不到clone的网速。首先要建立好socks5连接 。需要注意的地方就是填写自己的 sslocal 的参数信息

工作原理 执行 git clone git@github.com... 的时候,通过配置文件 ~/.ssh/config 浏览转发到 127.0.0.1:1080 然后交给 socks代理 进行处理。

yum -y install epel-release
yum -y install git tmux connect-proxy

type pip &> /dev/null

if [ $? -eq 1 ] ; then
        yum -y install python-pip
fi

pip install shadowsocks

sslocal  -s xxx.xxx.xxx.xxx -p xxxx -k 'xxxx' -m 'xxxx' -l 1080 -t 300  -l 1080 -d start

cat > ~/.ssh/config <<EOF
Host github.com
ProxyCommand connect-proxy -S 127.0.0.1:1080 %h %p
HostName %h
Port 22
User git
IdentityFile  ~/.ssh/id_rsa
IdentitiesOnly yes
EOF

# 若果不是root用户
chmod 600 ~/.ssh/config

测试连接

ssh -T git@github.com
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.

关闭 sslocal

yum -y install psmisc
killall sslocal
ssh -T git@github.com

FATAL: Unable to connect to relay host, errno=111
ssh_exchange_identification: Connection closed by remote host

从错误的信息可以看出连接失败。~/.ssh/config 把流量转移到了 127.0.0.1:1080, 之后因为 关闭了 sslocal 就结束了。

停止 ssh 流量的转移

echo >  ~/.ssh/config

 ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address 'xx.xx.xx.xx' to the list of known hosts.
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.

一个警告信息,还是提示成功了。这个是直接访问 github.com ,没有使用代理。

回复

您的电子邮箱地址不会被公开。