60

For the command

sudo apt-get update

I get following error:

W: Failed to fetch http://ch.archive.ubuntu.com/ubuntu/dists/maverick-updates/multiverse/binary-i386/Packages.gz  
407  Proxy Authentication Required (The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )

I am running Ubuntu 10.10 installed on Windows XP using VirtualBox. For Internet connections I am using proxy server with an authentication. I tried to use gnome-network-proxy tool to set proxy settings system-wide.

After that /etc/environment has been updated by http_proxy variable with the format http://my_proxy:port/, there were no authentication data.

I checked this with Firefox. Browser asked my for login and password and everything was working fine. It was unfortunately not the case for apt-get. I have also tried to do as described here. Unfortunately it does not work.

May it be somehow related to the fact that a proxy is in a Windows domain, any ideas?

My proxy name is http-proxy. Is '-' a special character here?

tommyk
  • 4,466

12 Answers12

60

For my corporate network I was given by my administrator the proxy name in the format:

http://[username]:[password]@[proxy-webaddress]:[port]

For our Windows network our username is in the format:

[domain]\[username]

For example:

http://mywindowsdomain\fossfreedom:password@askubuntu-proxy.com:8080

This was added to the following NEW file (it doesnt exist by default):

gksudo gedit /etc/apt/apt.conf.d/01proxy

The following text was added:

Acquire::http::Proxy "http://mywindowsdomain\fossfreedom:password@askubuntu-proxy.com:8080";

If you are using an anonymous proxy then you don't need your login credentials:

Acquire::http::Proxy "http://askubuntu-proxy.com:8080";

Save the file and then checked that all was ok with:

sudo apt-get update
Braiam
  • 67,791
  • 32
  • 179
  • 269
fossfreedom
  • 172,746
  • To those who will read this later: This seem like a hack to the untrained eye, but it is an incredibly simple way to get the corporate proxy to obey. – macduff Jun 26 '12 at 19:55
  • 2
    This works perfectly. UNLESS you have earlier set the /etc/apt/apt.conf with a bad Acquire line.

    I did just that, and all I had to do was go back and delete that line.

    – Skip Huffman Aug 17 '12 at 13:44
  • On Ubuntu 12.10, I had to copy the changes made to /etc/apt/apt.conf.d/01proxy to /etc/apt/apt.conf before it would work. – Stephen Niedzielski Mar 26 '13 at 19:18
  • even with these edits I couldn't get this to work for me with 12.04... but I managed to get this to work by using and configuring ntlmaps and pointing the apt.conf file to the intermediate proxy there. – monkut May 02 '13 at 07:54
  • The program 'gksudo' is currently not installed. You can install it by typing: sudo apt-get install gksu (which of course won't work without a proxy set up ...) Fortunately sudo works just fine. – T.E.D. Dec 30 '15 at 17:04
  • I've been pulling my hair out for 15 minutes trying to find out why my proxy config wasn't working until I saw this post: sudo apt-get update...lots of other posts on this topic leave out that vital little step – dkaczynski Aug 24 '17 at 17:53
13

I have found that USERNAME and PASSWORD entered into the "Network Proxy" applet does not get stored into the apt.conf file you must manually add the username and password in the /etc/apt/apt.conf file.

The "Network Proxy" applet only stores the hostname and the port.

The basic syntax is

Acquire::http::proxy "http://User:Password@host:port/";

Acquire::ftp::proxy "ftp://User:Password@host:port/";

Acquire::https::proxy "https://User:Password@host:port/";

If you are using Windows usernames and password follow this advice:

User = Domain/Username

(windows users use / not \)

If you are using Windows strong/complex password with special characters you must use the URL encoding for the values, for example an "@" in the password would be "%40".

fossfreedom
  • 172,746
MneMoth
  • 131
8

Try setting http_proxy to http://user:pass@proxyserver:port/

edit:
If setting http_proxy does not work try editing apt.conf. In
Ubuntu apt.conf is fragmented in /etc/apt/apt.conf.d/ directory.
In this directory edit /etc/apt/apt.conf.d/01ubuntu:

APT {
    Acquire {
        http {
            Proxy "http://user:password@server:port";
        };
    };
};

or try setting it using Synaptic: Settings -> Preferences -> Network
And then set your proxy settings in "Manual proxy configuration".

5

I'm behind a MS ISA proxy and I'm using Cntlm Authentication Proxy; in the apt.conf I have 4 lines; I've read somewhere that the last line must be empty, but I'm not sure about it. It works perfectly:

Acquire::http::proxy "http://127.0.0.1:3128/";
Acquire::ftp::proxy "ftp://127.0.0.1:3128/";
Acquire::https::proxy "https://127.0.0.1:3128/";
kos
  • 35,891
dEvil
  • 51
3

cntlm has a discovery option that helps find the right config to work with the NTLM auth of your network, try this:

cntlm -I -M http://test.com

copy and paste the results in /etc/cntlm.conf

restart cntlm

Jorge Castro
  • 71,754
tommyk
  • 4,466
  • 'cntlm' is currently not installed. You can install it by typing: sudo apt-get install cntlm (which if course won't work if my proxy isn't set right...) – T.E.D. Dec 30 '15 at 16:48
2
  1. Open terminal and add the following lines to /etc/apt/apt.conf.

    gksu gedit /etc/apt/apt.conf
    
  2. Add these 2 lines:

    Acquire::http::Proxy "http://user:pass@proxy-host:port/";
    Acquire::ftp::Proxy "http://user:pass@proxy-host:port/";
    
  3. Save and exit.

    Now apt-get update and should work behind a proxy, but you will notice that still something is not working, that is the add-apt-repository command.

    To be able to add repository behind a proxy, type the following commands:

    # export https_proxy="http://192.168.1.5:8080"
    # sed -i 's/"keyserver.ubuntu.com"/"hkp://keyserver.ubuntu.com:80"/' /usr/share`/pyshared/softwareproperties/ppa.py`
    

    Now you can add repositories in Lucid and Natty using LANG=C add-apt-repository

    Example:

    root@ubuntu:~# LANG=C add-apt-repository ppa:motumedia/mplayer-daily

Via Unixmen

Peachy
  • 7,117
  • 10
  • 38
  • 46
2

How to apply apt-get update or install in Ubuntu ? I was behind a proxy server and after installing Ubuntu i coulden`t update or install anything using the apt-get command. After searching i found that The apt package has been changed, now there is no more apt.conf on /etc/apt directory.

What i did to resolve this issue is the follow :

Open terminal and the file

sudo -H gedit /etc/bash.bashrc

and add at the bottom of the file these 2 lines :

#proxy 
export http_proxy=http://user:password@host:port/
export ftp_proxy=http://user:pass@host:port/

Now save and exit, Now you will be able to update, upgrade or install packages in Ubuntu

muru
  • 197,895
  • 55
  • 485
  • 740
hhlp
  • 42,002
  • I have added exports as you suggested. It still does not work. Now I got a different error message "Could not connect to extras.ubuntu.com:80 (91.189.88.33). - connect (110: Connection timed out)".
    Strange thing is that when I enter the same proxy settings in Firefox preferences then I can browse a web.
    – tommyk Jan 28 '11 at 13:58
  • @tommyk could you post your /etc/apt/sources.list and update your question here or try to delete extras.ubuntu.com from your /etc/apt/sources.list and execute apt-get update – hhlp Jan 28 '11 at 14:16
  • I've replaced my sources.list with a default one from ubuntu web page. I still got the same error for every repository listed in a this file. – tommyk Jan 28 '11 at 15:09
2

This one has been working for me!!

(adding proxy manually from the GUI via system-settings->network etc should work) But if doesn't and you export env variable from the terminal:

export http_proxy=http://<your proxy url>:<proxy port>

and again for https:

export https_proxy= <usually the same as the http>

Most important to add the -E: To run sudo apt-get install or sudo apt-get update you must run:

sudo -E <command>

The "-E" use your user environment variables for the root (sudo) , for that matter the http_proxy/https_proxy you've just exported.

Hope it helps :)

Kohn1001
  • 121
  • 2
1

Had this same issue after installing Ubuntu 18.04. What worked for me was to:

  1. Open Network Proxy screen in Network settings
  2. Select Manual and adding both http and https proxy info
  3. Additionally set Ignore Hosts field with:
    https://extensions.gnome.org*, *.extensions.gnome.org*
  4. Restarted Ubuntu

As for point 3, not sure if adding the above entry works or not but this step works for me

abu_bua
  • 10,783
Vuzi
  • 11
1

With a BlueCoat proxy, for me the format of the apt.conf file was required to look like:

Acquire::http::proxy "http://Domain%5cUserID:Password@proxy.name.whatever:80/";
Acquire::ftp::proxy "ftp://Domain%5cUserID:Password@proxy.name.whatever:80/";
Acquire::https::proxy "https://Domain%5cUserID:Password@proxy.name.whatever:80/";

^ ^ ^ ^ Blank line after 3rd proxy line, do not enter this line. ^ ^ ^ ^

Peachy
  • 7,117
  • 10
  • 38
  • 46
Jason
  • 11
1

This one-liner solution worked for me:

sudo env http_proxy=http://<ip>:<port> apt-get update
Raheel
  • 111
0
  1. Start Synaptic (go to System -> Administration -> Synaptic in Gnome 2, or type "synaptic" in the Dash in Unity).
  2. On the menu bar, click Settings, followed by Preferences.
  3. When the Preferences window appears, click on the Network tab.
  4. Select the Manual proxy configuration radio button and enter your proxy information.
  5. To apply authentication information, click the Authentication button and enter username and password.
  6. Click OK to close the HTTP Authentication window.
  7. Click OK to close the Preferences window.
  8. Click the Reload button to update the package lists.

Note that this setting change will also affect the Update Manager.