Ubuntu – How to allow a command to be executed for a particular user without password with sudoers file


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

Best Answer

  • 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.