man 5 sudoers
says:
When multiple entries match for a user, they are applied in order. Where there are multiple matches, the last match is used (which is not necessarily the most specific match).
So you should have these lines exactly in this order:
username ALL=(ALL) ALLusername ALL=(ALL) NOPASSWD: /home/username/script.sh
and any line that also matches (like e.g. %sudo ALL=(ALL:ALL) ALL
) should be before the NOPASSWD
line.
General note: #include
and #includedir
allow sudoers
to include other files. From the version 1.9.1 the encouraged directives are @include
and @includedir
respectively, but #include
and #includedir
are still accepted. Don't let #
fool you, these are not comments. While searching for entries that may interfere, you shouldn't omit what #include
and #includedir
point to. Helpful option: sudo -l
.