Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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: 91.189.91.14 80]

W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/precise-backports/multiverse/source/Sources 401 Authorization Required [IP: 91.189.91.14 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:

Options:
-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
share|improve this question

1 Answer 1

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.

#!/bin/bash
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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