underclassHero 2019-06-26
github 在国内访问一直不是很稳定,clone/push 等操作速度很慢。以下提供 https 和 ssh 这两种的访问方式的加速方法的配置,以及优缺点比较。
github 允许用户通过 https 端口使用 ssh,可以通过下面的指令测试
ssh -T -p 443 [email protected] Hi username! You've successfully authenticated, but GitHub does not provide shell access.
如果测试不通过,就需要修改配置文件 ~/.ssh/config,增加
Host github.com Hostname ssh.github.com Port 443
http 和 https 代理是非常常见的,比如我一般都是对系统全局代理https 协议,那么在github认证时只能使用提供 username/password 的方式认证,如果要避免每次push时都输入密码,需要一些额外的步骤。Caching your GitHub password in Git - User Documentationtwo-factor authentication,还需要提供 personal access token。Provide access token if 2FA enabled - User Documentation更多详情参考 Using SSH over the HTTPS port - User Documentation
前提:需要一个 socks5 代理
如果是直接通过 ssh 协议访问,则需要按照以下步骤配置
在 /usr/local/bin 增加一个文件,名为 git-proxy-wrapper,增加 +x 权限
ruhm@mac:~$ cat /usr/local/bin/git-proxy-wrapper #! /bin/bash nc -xlocalhost:1080 -X5 $*
注意,上面需要本机在 1080 端口打开 socks5 代理,端口可以自定义
~/.ssh/config 配置文件中内容如下
Host github.com
hostname github.com
User xxxxx
IdentityFile ~/.ssh/xxxxxx
ProxyCommand /usr/local/sbin/git-proxy-wrapper '%h %p'socks5 代理