I have a Ubuntu virtual machine that I use at work. I had previously been using this without any issues but there was an update put in that now requires all outbound connections to authenticate with our internal user name and password.

When I'm using the browser on my machine, this is not a problem, I can simply type my credentials and then move on, but when I'm running apt-get update (or any such command) I get bombed with failures:

W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/precise-backports/universe/source/Sources 401 Authorization Required [IP: 80]

W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/precise-backports/multiverse/source/Sources 401 Authorization Required [IP: 80]

Is there any way I can tell apt-get to stop and ask me to input my credentials when an Authorization request comes in, rather than just failing? I can't find any options in the help page about this:

-h  This help text.
-q  Loggable output - no progress indicator
-qq No output except for errors
-d  Download only - do NOT install or unpack archives
-s  No-act. Perform ordering simulation
-y  Assume Yes to all queries and do not prompt
-f  Attempt to correct a system with broken dependencies in place
-m  Attempt to continue if archives are unlocatable
-u  Show a list of upgraded packages as well
-b  Build the source package after fetching it
-V  Show verbose version numbers
-c=? Read this configuration file
-o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp

It's ugly, and insecure, but yes, you can.

See this web page for instructions on how to set up apt-get to use an http proxy that requires authentication; in particular, the section marked "How to login a proxy user".

There's also apt-get does not work with proxy, which outlines another method, but they both suffer from the same problem.

Your username and password are hard coded somewhere.

As an alternative, you could write a small shell script wrapper for apt-get, that could ask you for your username and password, and only set the environment variable in memory. It's still insecure, as process memory can be examined, but less so than having it hard coded in a file.

read -p "Username: " username
read -s -p "Password: " password
export http_proxy=http://${username}:${password}@yourproxyaddress:proxyport
sudo apt-get "$@"

Unfortunately, I don't think there's anything built-in to apt-get that would handle this for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.