Using Groups to Manage sudo Access
Assign sudo permissions to groups and add users as group members.
Instead of specifying different levels of sudo
access for each
individual user you can optionally manage sudo
access at group level by
adding the %
symbol to the group name.
For example, to define permissions for an existing group called example
in the /etc/sudoers.d/
directory and then add the user
alice
to that group:
-
Create the
/etc/sudoers.d/example
file by using thevisudo
command:sudo visudo /etc/sudoers.d/example
-
Grant the
example
group permissions to manage system services and software packages:%example ALL= SERVICES, SOFTWARE
-
Add the the
alice
user to theexample
group:sudo usermod -aG example alice
Or, you can set group permissions directly in the /etc/sudoers
file. For
example, to grant the user bob
full sudo
access on all
hosts, enable the existing group wheel
, and then add the user
bob
to it:
-
Open the
/etc/sudoers
file by using thevisudo
command without specifying a target file:sudo visudo
-
Remove the comment
#
symbol from the beginning of the following line in the/etc/sudoers
file:%wheel ALL=(ALL) ALL
-
Add the
bob
user to thewheel
group to grant them fullsudo
access on all hosts:sudo usermod -aG wheel bob