Root authorization via sudo (superuser do)

The sudo command allows a authenticated user to execute an authorized command as root.

Why use sudo?

How does it work? NOTE: You can install sudo via rpm or ftp the tar file from http://www.courtesan.com/sudo. Most Linux vendors provide sudo in their distribution.

Logging

Configuration
sudo determines whether a user is authorized to run a specific command as root by examining its configurations file, /etc/sudoers.

 

sudo config file
/etc/sudoers
sudo binary which prefaces each command,
sudo mount /mnt/distro
/usr/bin/sudo
sudo binary to edit suders file and check syntax,
sudo visudo
/usr/sbin/visudo

/etc/sudoers the sudo configuration file

sudoer aliases # User aliases
User_Alias          ADMINS=pattyo,joel
User_Alias          STUDENTS=tim,mary,jack

# Machine aliases
Host_Alias          SERVERS=ponto,oaxaca,colima
Host_Alias          SCIENCE=curie,salk,pasteur

# Command aliases
Cmnd_Alias          SHUT=/sbin/shutdown -r *
Cmnd_Alias          DUMP=/sbin/dump,/sbin/restore
Cmnd_Alias          SHELLS=/bin/sh,/bin/tcsh,/bin/bash,/bin/csh
Cmnd_Alias          PRINT=/usr/sbin/lpc,/usr/sbin/lprm

# Privileges
ADMINS              ALL=(ALL)ALL
STUDENTS            ALL,!SERVERS=(operator)SHUT,DUMP
kelly               ALL=NOPASSWD:PRINT
jimj,mikes          SCIENCE=(ALL)ALL,!SHELLS
dylan               goku=(ALL)ALL

After the aliases section (above), each permission line contains the following information

Explanation of Privileges in configuration file above:

visudo because the /etc/sudoers file can get very complicated

sudo Usage

   Example: the user kelly executing the lpc command on the server ponto:
[kelly@ponto]$ sudo /usr/sbin/lpc reread lp
lpd server pid 1184 on ponto.example.com, sending SIGHUP
   Example: the user jack trying to run the shutdown command on the server ponto:
[jack@ponto]$ sudo /sbin/shutdown -h now

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these two things:

 #1) Respect the privacy of others.
 #2) Think before you type.

Password:

jack is not allowed to run sudo on ponto.  This incident will be reported.

Jack (see alias STUDENTS in configuration file) is excluded from all rootly privileges on the machine ponto.

Sudo vulnerabilities

[mikes@ponto]$ sudo /bin/sh
Password:
Sorry, user mikes is not allowed to execute '/bin/sh' as root on ponto.

[mikes@ponto]$ cp -p /bin/csh /tmp/csh


[mikes@ponto]$ sudo /tmp/csh


[root@ponto]$ whoami

  root

Lab: Configure the sudoers file on your systems

Check that you have the sudo rpm installed
# rpm -qa sudo
Create the group admin on your machines
# groupadd admin
Make sure that your account is in the admin group
# usermod -G admin youracct
Create a student account (if it doesn't already exist)
# useradd student
Put the student account in the additional group users
# usermod -G users student
Check the /etc/passwd and /etc/group files for your modifications
# grep admin /etc/group
# grep youracct /etc/passwd
Modify the /etc/sudoers file using the visudo command
# visudo
  1. Configure the sudoers file so that the group admin has full control of your computer
  2. Configure the sudoers file such that the users group is able to restart the printer, shutdown the machine, and mount the cdrom