Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use Debian 6. I'm sitting behind a proxy, so I configured Debian to use that proxy. Browsing and any HTTP and FTP activity through GUI works OK.

I wanted to update my package repository so I typed in a shell:

sudo aptitude

then if I try to update the repo (pressing 'u') aptitude stops while trying to reach debian's FTP server, and this action will eventually time out.

But if it try:

$ su
# aptitude

updating works.

What is the difference between the two invocation? The $http_proxy and $ftp_proxy environment variables exist in both shells.

share|improve this question
up vote 2 down vote accepted

The su command starts another shell as root (or whomever if you supply a username and correct password). This shell gets all the normal environment variables, which of course includes the HTTP_PROXY and FTP_PROXY variables. Thus it works.

The sudo command REMOVES ALL environment variables except for a specifically chosen subset... which of course does NOT include the HTTP_PROXY & FTP_PROXY variables, thus your commands fail.

You can make sudo keep the *_PROXY variables by editing the sudoers config file, using the visudo command (of course).

Adding the following will make sudo keep the values of HTTP_PROXY & FTP_PROXY:

Defaults env_keep += "http_proxy ftp_proxy https_proxy HTTP_PROXY FTP_PROXY HTTPS_PROXY"

Coincidentally, if you add DISPLAY & HOME to that list, you can use gui programs with sudo too (they need the DISPLAY variable to connect)

Defaults env_keep += "DISPLAY HOME"

You can even just add those two lines, like that. (The += is the key here) Remember to add these lines towards the end of the file, since in the first few lines it usually sets the '*env_keep*' variable with a straight '=', which erases any previous value.

share|improve this answer
    
geez, I need to read documentation :-) thanks, worked perfectly. – karatedog Jul 6 '12 at 10:01

I was struggling with this myself and finally went with the solution proposed on Ask Ubuntu: apt-get does not work with proxy

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";
      };
  };
};
share|improve this answer
    
This is a fixed setting. I tried this, and it is useless for notebooks that move among different networks (it won't fall back to direct connection if it cannot find the proxy) – karatedog Jul 6 '12 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .