Initial Settings : Configure Sudo2025/08/11 |
|
Configure Sudo to separate users' duty if some people share privileges. |
|
| [1] | Install Sudo. |
|
root@localhost:~# apt -y install sudo |
| [2] | Transfer root privilege to a user all. |
|
root@localhost:~#
# add to last line : user [trixie] can use all root privilege # how to write ⇒ destination host=(owner) command trixie ALL=(ALL:ALL) ALL # push [Ctrl + x] key to quit visudo
# verify with user [trixie] trixie@localhost:~$ cat /etc/shadow
cat: /etc/shadow: Permission denied
# denied
trixie@localhost:~$ sudo cat /etc/shadow [sudo] password for trixie: # trixie's password root:xxxxxxxxxx:19520:0:99999:7::: daemon:*:19520:0:99999:7::: bin:*:19520:0:99999:7::: sys:*:19520:0:99999:7::: sync:*:19520:0:99999:7::: ..... ..... # possible executed |
| [3] | In addition to the setting [1], set that some commands are not allowed. |
|
root@localhost:~#
# add alias for the kind of shutdown commands # Cmnd alias specification Cmnd_Alias SHUTDOWN = /usr/sbin/halt, /usr/sbin/shutdown, \ /usr/sbin/poweroff, /usr/sbin/reboot, /usr/sbin/init, /usr/bin/systemctl # add ( commands in alias [SHUTDOWN] are not allowed ) trixie ALL=(ALL:ALL) ALL, !SHUTDOWN # verify with user [trixie] trixie@localhost:~$ sudo /usr/sbin/reboot [sudo] password for trixie: Sorry, user trixie is not allowed to execute '/usr/sbin/reboot' as root on localhost. # denied as setting
|
| [4] | Transfer some commands with root privilege to users in a group. |
|
root@localhost:~#
# add alias for the kind of user management commands # 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 to the end
%usermgr ALL=(ALL:ALL) USERMGR
# verify with user [trixie] trixie@localhost:~$ sudo /usr/sbin/useradd testuser trixie@localhost:~$ trixie@localhost:~$ sudo /usr/bin/passwd testuser Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully # possible execute
|
| [5] | Transfer some specific commands with root privilege to a user. |
|
root@localhost:~#
# add to the end : set specific commands to each user
fedora ALL=(ALL:ALL) /usr/sbin/visudo
debian ALL=(ALL:ALL) /usr/sbin/adduser, /usr/sbin/useradd, /usr/sbin/newusers, \
/usr/sbin/deluser, /usr/sbin/userdel, /usr/sbin/usermod, /usr/bin/passwd
ubuntu ALL=(ALL:ALL) /usr/bin/vim
# possible open and edit ## Sudoers allows particular users to run various commands as ## the root user, without needing the root password. ## # verify with user [debian] debian@localhost:~$ sudo /usr/sbin/userdel -r testuser
debian@localhost:~$
# possible execute
# verify with user [ubuntu]
ubuntu@localhost:~$
sudo /usr/bin/vim /root/.profile
# possible open and edit # ~/.profile: executed by Bourne-compatible login shells. |
| [6] | It's possible to display Sudo logs on Journald like follows. |
|
root@localhost:~# journalctl -t sudo Aug 10 18:20:48 debian sudo[1515]: pam_unix(sudo:auth): authentication failure; logname=root uid=1001 euid=0 tty=/dev/ttyS0 rus> Aug 10 18:20:54 debian sudo[1515]: trixie : TTY=ttyS0 ; PWD=/home/trixie ; USER=root ; COMMAND=/usr/bin/cat /etc/shadow Aug 10 18:20:54 debian sudo[1515]: pam_unix(sudo:session): session opened for user root(uid=0) by root(uid=1001) Aug 10 18:20:54 debian sudo[1515]: pam_unix(sudo:session): session closed for user root Aug 10 18:23:28 debian sudo[1545]: trixie : TTY=ttyS0 ; PWD=/home/trixie ; USER=root ; COMMAND=/usr/bin/cat /etc/passwd Aug 10 18:23:28 debian sudo[1545]: pam_unix(sudo:session): session opened for user root(uid=0) by root(uid=1001) Aug 10 18:23:28 debian sudo[1545]: pam_unix(sudo:session): session closed for user root Aug 10 18:23:33 debian sudo[1549]: trixie : TTY=ttyS0 ; PWD=/home/trixie ; USER=root ; COMMAND=/usr/bin/ls -l /root Aug 10 18:23:33 debian sudo[1549]: pam_unix(sudo:session): session opened for user root(uid=0) by root(uid=1001) Aug 10 18:23:33 debian sudo[1549]: pam_unix(sudo:session): session closed for user root |
| Sponsored Link |