WSL 使用proxy连接Github
WSL是win10/win11自带的Linux系统,经常开发时需要用到,但经常碰到无法连接GitHub下载资源的问题,本文介绍通过proxy来解决这个问题。
问题描述:
1.win中已有 proxy工具和端口号,win能够通过web连接到github,此处不用多说;
2. win开启proxy但WSL1连接不上 github
WSL1 开启 proxy步骤
WSL1可以直接通过本地host 127.0.0.1 利用win路径访问到github;所以使用 hostip + port方式可以解决问题
export hostip=127.0.0.1
export hostport=10808 // 取决于win的proxy工具设置的端口号
export HTTPS_PROXY="socks5://${hostip}:${hostport}";
export HTTP_PROXY="socks5://${hostip}:${hostport}";
export ALL_PROXY="socks5://${hostip}:${hostport}";
或者直接在
在~\.bashrc
中添加
# add for proxy
export hostip=127.0.0.1
export hostport=10808
alias proxy='
export HTTPS_PROXY="socks5://${hostip}:${hostport}";
export HTTP_PROXY="socks5://${hostip}:${hostport}";
export ALL_PROXY="socks5://${hostip}:${hostport}";
echo -e "Acquire::http::Proxy \"http://${hostip}:${hostport}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
echo -e "Acquire::https::Proxy \"http://${hostip}:${hostport}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
'
150 alias unproxy='
151 unset HTTPS_PROXY;
152 unset HTTP_PROXY;
153 unset ALL_PROXY;
154 sudo sed -i -e '/Acquire::http::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
155 sudo sed -i -e '/Acquire::https::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
156 '