Ubuntu 14.04
Sponsored Link

Configure sudo2014/04/18

 
Configure sudo to separate users' duty if some people share privileges.
[1] Install sudo
root@dlp:~#
apt-get -y install sudo

[2] Transfer root privilege to a user all.
root@dlp:~#
# add at the last: user 'trusty' can use all root privilege

trusty ALL=(ALL:ALL) ALL
# how to write ⇒ destination host=(owner) command

# push 'Ctrl + x' key to quit visudo
# make sure with user 'trusty'

trusty@dlp:~$
/sbin/shutdown -r now

shutdown: Need to be root
# denied normally

trusty@dlp:~$
sudo /sbin/shutdown -r now

[sudo] password for trusty:
# trusty's password

Broadcast message from root@dlp
        (/dev/pts/0) at 17:33 ...

The system is going down for reboot NOW!  
# executed
[3] In addition to the setting [1], set that some commands are not allowed.
root@dlp:~#
# add alias for the kind of shutdown commands

# Cmnd alias specification
Cmnd_Alias SHUTDOWN = /sbin/halt, /sbin/shutdown, \
/sbin/poweroff, /sbin/reboot, /sbin/init
# add ( commands in alias 'SHUTDOWN' are not allowed )

trusty
ALL=(ALL)
ALL,
!SHUTDOWN
# make sure with user 'trusty'

trusty@dlp:~$
sudo /sbin/shutdown -r now

[sudo] password for trusty:
Sorry, user trusty is not allowed to execute '/sbin/shutdown -r now' as root on dlp.srv.world.  
# denied normally
[4] Transfer some commands with root privilege to users in a group.
root@dlp:~#
# add aliase for the kind of user management comamnds

# Cmnd alias specification
Cmnd_Alias USERMGR = /usr/sbin/adduser, /usr/sbin/useradd, /usr/sbin/newusers, \
/usr/sbin/deluser, /usr/sbin/userdel, /usr/sbin/usermod, /usr/bin/passwd
# add at the last

%usermgr ALL=(ALL) USERMGR
root@dlp:~#
groupadd usermgr

root@dlp:~#
vi /etc/group
# add a user in this group

usermgr:x:1002:
trusty
# make sure with user 'trusty'

trusty@dlp:~$
sudo /usr/sbin/useradd testuser

trusty@dlp:~$
# done normally

trusty@dlp:~$
sudo /usr/bin/passwd testuser

Enter new UNIX password:
# set testuser's password

Retype new UNIX password:
passwd: password updated successfully
[5] Transfer a command with root privilege to a user.
root@dlp:~#
# add at the last

fedora
ALL=(ALL) /usr/sbin/visudo

cent
ALL=(ALL) /usr/sbin/adduser, /usr/sbin/useradd, /usr/sbin/newusers, \

/usr/sbin/deluser, /usr/sbin/userdel, /usr/sbin/usermod, /usr/bin/passwd

suse
ALL=(ALL) /usr/bin/vim
# make sure with user 'fedora'

fedora@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 user 'cent'

cent@dlp:~$
sudo /usr/sbin/userdel -r testuser

cent@dlp:~$
# done normally
# make sure with user 'suse'

suse@dlp:~$
sudo /usr/bin/vim /root/.profile
# possible to open and edit

# ~/.profile: executed by Bourne-compatible login shells.
[6] The logs for sudo are kept in '/var/log/auth.log', 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:~#
# add at the last

Defaults syslog=local1
root@dlp:~#
vi /etc/rsyslog.d/50-default.conf
# line 8: add

local1.*                        /var/log/sudo.log
auth,authpriv.*                 /var/log/auth.log
*.*;auth,authpriv.none          -/var/log/syslog

root@dlp:~#
initctl restart rsyslog

rsyslog start/running, process 1969
Matched Content