Linux命令行及各常用工具代理設置
命令行代理設置
1 通過命令行指定
直接為當前命令行設置代理
- 對當前終端的全部工具(apt、curl、wget、git 等全都有效)
- 以下僅以 http 代理為例,如果是其他協議(如 socks 等)自行改變協議名
# 設置代理
# export http_proxy=http://proxyAddress:port
# 如果需要賬戶名密碼:export http_proxy=http://userName:password@proxyAddress:port
# 或者加上:export http_proxy_user=username; export http_proxy_pass=passwd
# 例如:
set http_proxy="http:127.0.0.1:7890"
set https_proxy="http:127.0.0.1:7890"# 取消代理
unset http_proxt
unset https_proxt
測試:
curl www.google.com
2 在bashrc中指定
將上述環境變量的設置寫到 ~/.bashrc
中即可。
curl設置代理
1 參數選項指定
通過 -x
參數指定代理:
curl -x 127.0.0.1:7890 https://www.google.com
2 配置文件指定
在 ~/.curlrc
中進行設置:
echo proxy="http://127.0.0.1:5000" >> ~/.curlrc
curl www.google.com
wget代理設置
1 參數選項指定
注意這其實不是 wget 命令本身的參數選項,而相當于是在命令行上指定一個原本出現在 wgetrc
中的設置:
wget www.google.com -e "http_proxy=http://127.0.0.1:7890"
2 配置文件指定
在 /etc/wgetrc
中找到下列內容,按需修改為自己的代理服務器即可。
注意如果不想每次默認使用代理,可以不打開 use_proxy = on
,而是在每次命令中通過 -Y
或 --proxy
選項為 on/off
來指定。
# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy = http://proxy.yoyodyne.com:18023/
http_proxy = http://proxy.yoyodyne.com:18023/
ftp_proxy = http://proxy.yoyodyne.com:18023/# If you do not want to use proxy at all, set this to off.
use_proxy = on
git代理設置
1 命令行指定
# 設置代理
git config --global https.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
git config --global http.https://github.com.proxy http://127.0.0.1:7890 # 僅對github設置代理# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
2 通過配置文件指定
將代理寫到配置文件 ~/.gitconfig
中,如:
[http]proxy = http://127.0.0.1:1080
Ref:
https://blog.csdn.net/lovedingd/article/details/118824049
https://blog.imdst.com/untitledlinuxxia-she-zhi-gitdai-li-fang-wen/
https://www.lmlphp.com/user/58209/article/item/1457465/