方法:把socks5代理服务器地址写入用户主目录的
~/.bashrc
文件或/etc/profile
文件,然后使用source [File]
命令使配置的内容在当前回话生效;
在~/.bashrc
文件或/etc/profile
文件文中添加普通HTTP代理的内容如下:
export http_proxy="http://localhost:port"
export https_proxy="http://localhost:port"
以使用shadowsocks
代理为例,ssr
的代理端口为1080
,那么应该设置为:
export http_proxy="socks5://127.0.0.1:1080"
export https_proxy="socks5://127.0.0.1:1080"
也可以直接设置ALL_PROXY
export ALL_PROXY=socks5://127.0.0.1:1080
保存好文件后,接着在终端中执行:
source ~/.bashrc
## 或者执行:
source /etc/profile
或者退出当前终端再起一个终端。 这个办法的好处是把代理服务器永久保存了,下次就可以直接用了。
另外我们还可以通过设置alias简写来简化操作,每次要用的时候输入setproxy,不用了就unsetproxy。方法就是讲下列命令添加在~/.bashrc
文件或/etc/profile
文件中,具体命令如下:
alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1080"
alias unsetproxy="unset ALL_PROXY"
对于程序员而言,在从GitHub中使用git clone
命令拉取代码比较慢的情况,也可以用ssr来加快git的速度,具体配置命令如下:
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'