Sudo Configuration File Syntax
In this step, you will learn about the syntax of the /etc/sudoers
file, which is used to configure sudo privileges.
The /etc/sudoers
file is used to specify which users or groups can run commands with elevated privileges. To view and save the contents of the /etc/sudoers
file, run the following command:
sudo cat /etc/sudoers | grep root > /home/labex/project/sudoers.txt
The output should look similar to the following:
## This file MUST be edited with the 'visudo' command as root.
## This preserves proxy settings from user environments of root
## While you shouldn't normally run git as root, you need to with etckeeper
## Per-user preferences; root won't have sensible values for them.
root ALL=(ALL:ALL) ALL
## Members of the admin group may gain root privileges
This line specifies that the root
user can run any command as any user or group on all hosts.
The general syntax for a sudoers
entry is:
user_or_group_name host_list=(run_as_user:run_as_group) command_list
user_or_group_name
: The user or group to whom the rule applies.
host_list
: The host(s) on which the rule applies. The value ALL
means all hosts.
run_as_user
: The user whose privileges are used to run the command. The value ALL
means any user.
run_as_group
: The group whose privileges are used to run the command. The value ALL
means any group.
command_list
: The command(s) that the user or group is allowed to run.