3

Can anyone please explain the exact work of these in /etc/sudoers ? (I've done some research, so please don't share any links)

I want to add myself (member of sudo) to execute a command without password.But it's again asking for password.

# User

    root  ALL=(ALL:ALL) ALL

    myself  ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*

# Groups 

    %sudo   ALL=(ALL:ALL) ALL
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497

4 Answers4

4

I pretty much stole it from here: Is it possible to give sudo access to only a particular command?

sudo visudo -f /etc/sudoers.d/Username

And add that to the file:

Username ALL = NOPASSWD: /usr/bin/apt* update
Username ALL = NOPASSWD: /usr/bin/apt* install

Don't know how to make this a one-liner, though. Hope that helps.

3

The order of configuration lines has significance in the sudoers file: the last applicable line wins.

If user myself is a member of the sudo group, all commands issued by that user will always match the %sudo ALL=(ALL:ALL) ALL line. As it has no NOPASSWD: flag, password will be asked.

The fix is to arrange the /etc/sudoers configuration lines in the order of increasing specificity:

# Groups 

    %sudo   ALL=(ALL:ALL) ALL

# User

    root  ALL=(ALL:ALL) ALL

    myself  ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*

When this order is used, if user myself runs sudo apt update, it will match the last line with the NOPASSWD: flag.

telcoM
  • 294
1

This is my first post on askubuntu but i am pretty sure you could do it like that create a file with your username in /etc/sudoers.d/ with:

username ALL = NOPASSWD: ALL
  • 1
    NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient. – Sergiy Kolodyazhnyy Jan 11 '19 at 08:47
0

You can simple add the next line to your sudoers file:

username ALL=NOPASSWD: command1, command2, command3 [...]

Remember to separated with commas all commands you want to be executed by user with out password promp.