Score:0

How to include apt in sudoers without password

us flag

I want to authorize user daniel to use apt with any arguments without enter the password. NOT apt-get or aptitude. The APT command:

  • sudo apt update
  • sudo apt dist-upgrade
  • sudo apt list -a <match>
  • sudo apt search <match>
  • sudo apt install <match>
  • sudo apt purge <match>
  • sudo apt <anything>

I am trying with a custom /etc/sudoers.d/daniel and my sudoers file is unchanged and has the lines:

# See sudoers(5) for more information on "@include" directives:
@includedir /etc/sudoers.d

My /etc/sudoers.d/daniel:

# Allow daniel to execute apt without password
daniel ALL=(ALL:ALL) NOPASSWD:/usr/bin/apt

But it's not working. I tried also:

daniel ALL=(ALL:ALL) NOPASSWD:/usr/bin/apt *

But no success.

But it works for apt-fast...

daniel ALL=(ALL:ALL) NOPASSWD:/usr/bin/apt-fast
waltinator avatar
it flag
Read `man sudoers`.
Nerun avatar
us flag
I read. The solution seems to be: `daniel ALL=(root) NOPASSWD:^/usr/bin/apt.*$`. But did not test it yet, i am at phone.
Nerun avatar
us flag
No, doesn't work. But `/usr/bin/apt*` works for apt-get and apttude.
waltinator avatar
it flag
Avoid using the wildcard, `/usr/bin/apt`. In `man sudoers`, did you read down to the end?
Nerun avatar
us flag
If `daniel ALL=(ALL:ALL) NOPASSWD: /usr/bin/apt` i can execute **apt update** without password, but not **sudo apt update**. Weird. Yes i did read down to the end. What i am missing? Thank you for the help.
Score:0
us flag

Ok, i have found a solution to my own question.

Usually $ sudo apt (...) or just $ apt (...) need a password to be executed, as well as apt-get, aptitude and apt-fast (the latter a download accelerator).

With this solution is possible to execute any of them with sudo without password, BUT apt (not apt-get), to be executed without password, must not be executed with sudo (as in $ sudo apt update, but just $ apt update instead).

username ALL = NOPASSWD: /usr/bin/apt, /usr/bin/apt-get,\
                         /usr/bin/aptitude, /usr/bin/apt-fast
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.