Sudo
------
Configure sudo
[1]
Configure sudo to separate users' duty if some people share privileges.
It's unnecessarry to install sudo manually because it is installed by default even if "Minimal Install".
# sudo su -
Transfer root privilege to a user all.
[root@dlp ~]# visudo
# add at the last line: user 'cent' can use all root privilege
cent ALL=(ALL) ALL
# how to write ⇒ destination host=(owner) command
# make sure with the user 'cent'
[cent@dlp ~]$ /usr/bin/cat /etc/shadow
cat: /etc/shadow: Permission denied# denied normally
[cent@dlp ~]$ sudo /usr/bin/cat /etc/shadow
[sudo] password for cent:# own password
daemon:*:16231:0:99999:7::: adm:*:16231:0:99999:7::: lp:*:16231:0:99999:7::: ... ...
# just executed
[2]
In addition to the setting [1], set that some commands are not allowed.
[root@dlp ~]# visudo
# near line 49: add aliase for the kind of shutdown commands
Cmnd_Alias SHUTDOWN = /sbin/halt, /sbin/shutdown, \
/sbin/poweroff, /sbin/reboot, /sbin/init
# add ( commands in aliase 'SHUTDOWN' are not allowed )
centALL=(ALL)ALL, !SHUTDOWN
# make sure with the user 'cent'
[cent@dlp ~]$ sudo /sbin/shutdown -r now
Sorry, user cent is not allowed to execute '/sbin/shutdown -r now' as root on dlp.srv.world. # denied normally
[3]
Transfer some commands with root privilege to users in a group.
[root@dlp ~]# visudo
# near line 51: add aliase for the kind of user management comamnds
Cmnd_Alias USERMGR = /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, \
/usr/bin/passwd
# add at the last line
%usermgr ALL=(ALL) USERMGR
[root@dlp ~]# groupadd usermgr
[root@dlp ~]# usermod -G usermgr cent
# make sure with the user 'cent'
[cent@dlp ~]$ sudo /usr/sbin/useradd testuser
[cent@dlp ~]$ # done normally
[cent@dlp ~]$ sudo /usr/bin/passwd testuser
Changing password for user testuser.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[4]
Transfer a command with root privilege to a user.
[root@dlp ~]# visudo
# add at the last line
cent ALL=(ALL) /usr/sbin/visudo fedora ALL=(ALL) /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, /usr/bin/passwd ubuntu ALL=(ALL) /bin/vi
# make sure with the user 'cent'
[cent@dlp ~]$ sudo /usr/sbin/visudo
# possible to open and edit
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
# make sure with the user 'fedora'
[fedora@dlp ~]$ sudo /usr/sbin/userdel -r testuser
[fedora@dlp ~]$ # done normally
# make sure with the user 'ubuntu'
[ubuntu@dlp ~]$ sudo /bin/vi /boot/grub/grub.conf
# possible to open and edit
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
[5]
The logs for sudo are kept in '/var/log/secure', but there are many kind of logs in it. So if you'd like to keep only sudo's log in a file, Set like follows.
[root@dlp ~]# visudo
# add at the last line
Defaults syslog=local1
[root@dlp ~]# vi /etc/rsyslog.conf
# line 54: add
*.info;mail.none;authpriv.none;cron.none;local1.none /var/log/messages
# add the line, too
local1.* /var/log/sudo.log
[root@dlp ~]# systemctl restart rsyslog
------