Home > front end >  How do I enable passwordless sudo for all options for a command?
How do I enable passwordless sudo for all options for a command?

Time:08-24

I'd like to enable passwordless sudo for sudo apt update, and also have passwordless sudo work for the apt update command when I run it with options like sudo apt update -q and sudo apt update -qq.

I have the file /etc/sudoers.d/apt with these contents:

%sudo ALL=(root) NOPASSWD: /usr/bin/apt update

This gives me passwordless sudo for sudo apt update, but passwordless sudo fails when I call the command with an option such as sudo apt update -q.

I know I can account for options by listing out each one in /etc/sudoers.d/apt, but I'd prefer something which will work for all available options without me needing to foresee which ones I might want to use in the future.

CodePudding user response:

I can not test it right now, but according to the link, you could use wildcards:

%sudo ALL=(root) NOPASSWD: /usr/bin/apt update *

Again, I could no test it - Be careful as always, when you edit the suders file.

Source: https://www.sudo.ws/docs/man/1.7.10/sudoers.man/#Wildcards

CodePudding user response:

The most robust way that I can see to do this is:

%sudo ALL=(root) NOPASSWD: /usr/bin/apt update, /usr/bin/apt * update, /usr/bin/apt update *

The /usr/bin/apt update makes the basic command sudo apt update passwordless.

The /usr/bin/apt * update makes adding an option first like sudo apt -q update passwordless.

The /usr/bin/apt update * makes adding an option last like sudo apt update -q passwordless.

All of these are needed to handle the different ways the command might be called, and the different possible placements of options in the command.

Credit to Tobias' answer for pointing me in the right direction on this.

  • Related