在~/.ssh/config 输入:
Host github.com
HostName ssh.github.com
Port 443
IdentityFile "~/.ssh/id_rsa"
# -X后接使用的协议, 4 = socks4, 5 = socks5, connect = http
ProxyCommand nc -X connect -x 172.19.64.1:7890 %h %p
在~/.bashrc 输入:
sed -i "/^Host github.com$/{N;/Host.*HostName/{N;/Host.*HostName.*Port/{N;s/Port.*Proxy.*%p$//}}}" ~/.ssh/config
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*');
alias setproxy='export https_proxy="https://${hostip}:7890"; \
export http_proxy="http://${hostip}:7890"; \
export all_proxy="socks5://${hostip}:7890"; \
export ALL_PROXY="socks5://${hostip}:7890"; \
sed -i "s, *ProxyCommand.*$, ProxyCommand nc -X connect -x $hostip:7890 %h %p,g" ~/.ssh/config'
alias unsetproxy='unset https_proxy; \
unset http_proxy; \
unset all_proxy; \
unset ALL_PROXY;'
相关配置:
此时可以用wget测试。如果克隆https链接报错:
GnuTLS recv error (-110): The TLS connection was non-properly terminated.
参考这个链接,可以通过以下代码解决:
git config --global https.https://github.com.proxy https://$hostip:7890