2

When I run sudo apt-install <pkgname>, there is no password request.

How can I enforce a password check whenever this command is run? Why isn't it asking by default? Isn't that the point of sudo? Perhaps I might have mis-configured something so that this is bypassed?

How can I ensure that a password request is issued when I run an apt-get install <pkgname> command?

Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83
  • Also see http://askubuntu.com/questions/14948/how-to-cancel-the-currently-applied-remaining-sudo-time-out for sudo -k – Takkat Jan 03 '17 at 14:07
  • You might have already used sudo once. It caches your password. Does this happen always or sometimes? –  Jan 04 '17 at 01:19

3 Answers3

3

sudo caches your elevated privilege for about 15 minutes (sudo, sudoedit - execute a command as another user | Ubuntu Manpage) It's likely you didn't get asked for a password because you'd already entered it within that time. You can change the default by editing /etc/sudoers by typing sudo visudo eg:

Defaults:user637251 timestamp_timeout=30

see: Change sudo default password timeout | ScottLinux Blog

slowko
  • 942
  • Thanks @siloko - that makes total sense! I'm new to ubuntu to this is a noob question. appreciate the fast response too! – user637251 Jan 03 '17 at 14:16
2

Normally you will run sudo apt-get install ... and sudo will ask for your password the first time sudo is called and cache the password for 10 or 15 minutes, so the next calls to sudo doesn't require a password.

If you run apt-get install ... from root prompt, it will never ask for password.

amc
  • 7,142
Soren A
  • 6,799
1

You can also reset the time-stamp, whenever you want to execute apt-get command as below:

sudo -k && sudo apt-get install package_name

From man sudo : '-k' invalidates the user's cached credentials