嗨,我正在使用ubuntu服务器。我使用以下方法设置了代理:
echo "export http_proxy='http://username:password@proxyIP:port/'" | tee -a ~/.bashrc
我设置了http,https和ftp代理。 Wget
工作正常,但apt-get
无法连接。请帮忙!
apt-get
但我从来没有yum来处理环境变量。相反,我必须通过其配置设置代理。
这是apt-get conf的相关帖子:
https://askubuntu.com/questions/89437/how-to-install-packages-with-apt-get-on-a-system-connected-via-proxy
也。。。默认情况下,位于公共可读文件中的纯文本密码有多棒!(或环境变量和 bash 历史记录)
您需要更新 .bashrc 和 apt.conf 才能正常工作。
以下链接将详细解释这一点。http://codewithgeeks.blogspot.in/2013/11/configure-apt-get-to-work-from-behind.html
>apt-get
设置为忽略系统默认代理设置。
要设置代理,您必须转到/etc/apt/apt.conf 文件并添加以下行:
Acquire::http::proxy "http://username:password@proxyIP:port/";
Acquire::ftp::proxy "ftp://username:password@proxyIP:port/";
Acquire::https::proxy "https://username:password@proxyIP:port/";
您还可以创建一个脚本来设置此设置,并在需要时取消设置此脚本。
创建脚本 aptProxyOn.sh
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root";
exit 1;
fi
if [ $# -eq 2 ]
then
printf
"Acquire::http::proxy "http://$1:$2/";n
Acquire::ftp::proxy "ftp://$1:$2/";n
Acquire::https::proxy "https://$1:$2/";n" > /etc/apt/apt.conf.d/01proxies;
sudo cp /etc/apt/apt.conf.d/01proxies /etc/apt/apt.conf
else
printf "Usage $0 <proxy_ip> <proxy_port>n";
fi
若要删除代理,请创建名为 aptProxyOff.sh 的脚本
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root";
exit 1;
fi
printf "" > /etc/apt/apt.conf.d/01proxies;
sudo cp /etc/apt/apt.conf.d/01proxies /etc/apt/apt.conf
授予两个文件运行的权限。 chmod +x aptProxyOn.sh aptProxyOff.sh
您必须按以下方式运行它们。
代理打开 -
sudo ./aptProxyOn.sh username:password@proxyIP port
代理关闭 -
sudo ./aptProxyOff.sh
提示:
如果您的用户名或密码中有@,则它将无法直接工作。您必须使用 @ 的 URL 编码,即 %40。但是在传递命令行参数时,不能使用 %40,必须使用 %%40
这对我来说效果最好:
切换到/etc/apt 目录
编辑以下文件,如果该文件不存在,此命令将创建一个
gedit/apt.conf.d/apt.conf
并添加以下行
Aquire::http::p roxy "http://[proxy-server]:[port]";
Aquire::https::p roxy "https://[proxy-server]:[port]";