First line has correct syntax.
user1 ALL=(ALL) NOPASSWD: /etc/init.d/service-script
It means: user1 can, on ALL hosts that use this /etc/sudoers
file, become ALL users to run /etc/init.d/service-script
without a password request.
The second line has incorrect syntax, at least for modern versions of sudo
. If you edited /etc/sudoers
with the recommended visudo
command, you would get a message similar to this after exiting your favorite editor:
File /etc/sudoers.tmp saved
>>> /etc/sudoers: syntax error near line 28 <<<
What now?
By typing a question mark, you would get a list of options:
Options are:
(e)dit sudoers file again
e(x)it without saving changes to sudoers file
(Q)uit and save changes to sudoers file (DANGER!)
What now?
It would be best to select either 'e' and remove the incorrect line, or 'x' to discard all edits you made this time.
You might want to type a comment like this in your /etc/sudoers
file to remind you of the correct syntax:
# WHO WHERE = (AS WHOM) WHAT
Between the (AS WHOM)
and WHAT
parts, you can optionally add a few colon-terminated tags that can affect some details of the procedure.
Since the service-script is located in /etc/init.d, it apparently is intended to be run as root. So the "optimal" /etc/sudoers line would be:
user1 ALL=(root) NOPASSWD: /etc/init.d/service-script
The user should run it as:
sudo /etc/init.d/service-script
or explicitly
sudo -u root /etc/init.d/service-script
Adding arguments to the end of the command line is allowed.