How to give nopasswd access to multiple commands via sudoers?

I have solved the issue by creating a new group for limited admin rights... name of that group is LimitedAdmins after that I updated the sudoers file as below.

The line I appended is:

%LimitedAdmins ALL=NOPASSWD: /usr/bin/apt-get*, /etc/init.d/apache2 restart

This is the complete /etc/sudoers file:

# This file MUST be edited with the 'visudo' command as root.    
#   
# Please consider adding local content in /etc/sudoers.d/ instead of directly modifying   his file.   
#   
# See the man page for details on how to write a sudoers file.  
# 
Defaults    env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL  

#includedir /etc/sudoers.d
%domain_name\\administrators ALL=(ALL) ALL
%LimitedAdmins ALL=NOPASSWD: /usr/bin/apt-get*, /etc/init.d/apache2 restart

It works perfectly fine in case if your system is domain or not.


Looks like comma is what you need.

Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm
...
user3 ALL= PRINTING

Source


FWIW, I was wondering the same thing as the OP, and it looks like you can as well just duplicate the lines, e.g.

user_name ALL=NOPASSWD: cmd1
user_name ALL=NOPASSWD: cmd2
user_name ALL=NOPASSWD: cmd3

What I ended up doing was (Similar to what you are looking for):

## PRTG monitoring
Cmnd_Alias PRTG = /bin/cat /proc/loadavg, /bin/df, /var/prtg/scripts/check_proc.sh
prtg ALL = NOPASSWD: PRTG

Inside: /etc/sudoers.d/666-prtg

(666, because... well... prtg IS a windows based monitoring tool you know)