nknu.net

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-F2 then 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-hosts field. 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 the mode to auto, and enter the URL of the autoconfig script ing the autoconfig-url field. 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, replacing username, password, proxy_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 !

Adrien Anceau
Geek, gamer, photography enthusiast, passionate about technology, automation and food.
comments powered by Disqus
Back to Top