Ubuntu 14.04 proxy代理配置用戶名和密碼

http://www.nknu.net/ubuntu-14-04-proxy-authentication-config/

Ubuntu 14.04 proxy config with authentication

Updated the 07 Aug 2014: added autoconfig URL settings

If you're behind a company proxy, chances are that you need to use proxy authentication to have access to the outside world. The thing is that in Ubuntu, the default proxy configuration interface does not let you enter any credential, only the proxy address.

You have several options to work arround that.

Note: Some applications don't respect the settings defined by those methods. In that case, you'll have to refer to their documentation to configure the proxy.

1. The apt-get/click'ish way

Install the package dconf-editor (using the Ubuntu Software Center or simply typing sudo apt-get install dconf-editor in your terminal), and open it (hit alt-F2then type dconf-editor).

In the dconf Editor window, go to dconf-editor -> system -> proxy -> http and configure your username and password.

If you have local domains/ip/masks you don't want to use the proxy with, you can configure them in the dconf-editor -> system -> proxy window, in the ignore-hostsfield. For example if your company use an internal network name mycompany.lan, you can add *.mycompany.lan to avoid using the proxy when accessing this domain.

Note that if your network provides an autoconfig script, you can use it here. Set themode to auto, and enter the URL of the autoconfig script ing the autoconfig-urlfield. When you use the auto mode, every other setting exept autoconfig-url is ignored. If you have a windows box autoconfigured on the same network, an easy way to get the autoconfig URL is to open chrome and type chrome://net-internals/#proxy in the URL bar. The PAC script line is what you're looking for:

2. The console'ish way

If you don't want to use dconf-editor, or if you use another flavor of Linux, your can use this second method.

Create a .proxy file in your home directory. Have it only read/write-able by yourself, as we will store your credentials in there (including your password).

touch ~/.proxy
chmod 600 ~/.proxy

Open it with your favorite text editor and add the following content, replacingusernamepasswordproxy_hostname and proxy_port by their actual values:

# Proxy config
export http_proxy='username:password@http://proxy_hostname:proxy_port'
export no_proxy=’localhost,127.0.0.1,.mycompany.lan’

export https_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export NO_PROXY=$no_proxy

With that option, the no_proxy variable let you set a list of IP/mask/domains to ignore. Note that the domain syntax is slightly different than the dconf-editor one: only .mycompany.net withouth any wildcard.

Edit your ~/.profile file and add the following lines, which will load the content of the file we just created when you start your session.

# include proxy config if it exists
if [ -f $HOME/.proxy ]; then
    . $HOME/.proxy
fi

Log out and log back in, and your proxy settings should be taken into account.

Note that APT does not respect this setup. In order to have it use your proxy, you will have to edit the /etc/apt/apt.conf file (create it if it does not exist) and add the following line:

Acquire::http::Proxy "http://username:password@my.proxy.host:port";

Optionnal step: if you want your proxy setting to be propagated when you're using sudo, open the sudo config file with sudo visudo and add the following line after the other Defaults lines:

Defaults    env_keep += "http_proxy https_proxy no_proxy"

I hope it helped !


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值