4.1 Understanding Sudo
4.1 Understanding Sudo
2
1 sudoers file : Definition
The sudoers file (/etc/sudoers by default) is the “List of who can run what”. The file
is basically built over 2 kind of data :
Aliases : Aliases are variables that stores multiples entries that fit the same domain
(users, hosts, commands).
3
Alias:
4
Alias:
# Host alias specification ##
5
Users specifications : This is where all informations are compiled into a
effective one-liner.
sudo : Usage
sudo 'command’
Check whether or not you are in the sudoers file and what are the
forbidden/allowed commands for you or another user with a “-U” option :
sudo -l or sudo -ll (for a long list format) or sudo -l -U
6
visudo : The tool
When working on the sudoers file, you should use one tool
visudo.
sudoers : Basics
7
When you first open the sudoers file the only not-commented line is :
root ALL=(ALL) ALL
user hosts=(users:groups) commands
Let’s use this to explain the basic of the sudoers syntax. We can see that there are
4 fields as :
This can be literally said as : The user root (1) can execute ALL commands (4) as
ALL users (3) from ALL places (2).
8
The basic syntax of the sudoers file could be described as :
9
2.3 Basic examples
Here are some basic examples that may help you understand the
basics of the sudoers file.
Allow the user pier to run ALL commands from anywhere as root:
pier ALL=(ALL) ALL
10
Allow the user paul to run yum, mount and ifconfig commands
from anywhere as root:
paul ALL=(ALL) /usr/bin/yum, /sbin/mount, /sbin/ifconfig
11
Aliases
Aliases : Aliases are variables that stores multiples entries that fit
the same domain (users, hosts, commands).
There are 4 kind of Aliases as :
*User_Alias ==> for listing users
*Runas_Alias ==> for listing users a given user can run as,
*Host_Alias ==> for listing hosts
*Cmnd_Alias ==> for listing commands.
12
User_Alias MANAGERS = steve,bill,james
13
END of this Course Module.
Thanks
14