Fedora 37  

 
Định cấu hình Sudo để phân tách nhiệm vụ của người dùng nếu một số người chia sẻ đặc quyền.
Không cần cài đặt sudo thủ công vì nó được cài đặt theo mặc định ngay cả khi môi trường được cài đặt tối thiểu.
[1] Chuyển tất cả đặc quyền root cho người dùng.
[root@dlp ~]#
visudo
# add to the end : user [fedora] can use all root privilege

fedora  ALL=(ALL)       ALL
# how to write ⇒ destination host=(owner) command
# verify with user [fedora]

[fedora@dlp ~]$
/usr/bin/cat /etc/shadow

/usr/bin/cat: /etc/shadow: Permission denied  
# denied normally
[fedora@dlp ~]$
sudo /usr/bin/cat /etc/shadow

Password:    
# user's password
.....
.....
systemd-coredump:!*:19312::::::
systemd-timesync:!*:19312::::::  
# just executed
[2] Ngoài cài đặt [1], hãy đặt một số lệnh cấm.
[root@dlp ~]#
visudo
# line 49 : add
# for example, set aliase for the kind of shutdown commands

Cmnd_Alias SHUTDOWN = /usr/sbin/halt, /usr/sbin/shutdown, \
/usr/sbin/poweroff, /usr/sbin/reboot, /usr/sbin/init, /usr/bin/systemctl

# add ( prohibit commands in aliase [SHUTDOWN] )

fedora  ALL=(ALL)       ALL, !SHUTDOWN

# verify with user [fedora]

[fedora@dlp ~]$
sudo /usr/sbin/reboot

[sudo] password for fedora:
Sorry, user fedora is not allowed to execute '/usr/sbin/reboot' as root on dlp.srv.world.  
# denied normally
[3] Chuyển một số lệnh có quyền root cho người dùng trong một nhóm.
[root@dlp ~]#
visudo
# line 51 : add
# for example, set aliase for the kind of user managment commands

Cmnd_Alias USERMGR = /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, \
/usr/bin/passwd

# add to the end

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

[root@dlp ~]#
usermod -aG usermgr redhat

# verify with user [redhat]

[redhat@dlp ~]$
sudo /usr/sbin/useradd testuser

[redhat@dlp ~]$
sudo /usr/bin/passwd testuser

Changing password for user testuser.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.  
# executed
[4] Chuyển lệnh có quyền root cho người dùng.
[root@dlp ~]#
visudo
# add to the end: settings for each user

fedora  ALL=(ALL)       /usr/sbin/visudo
ubuntu  ALL=(ALL)       /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, /usr/bin/passwd
debian  ALL=(ALL)       /usr/bin/vi

# for example, verify with user [fedora]

[fedora@dlp ~]$
sudo /usr/sbin/visudo
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##  
# just executed
[5] Có thể hiển thị nhật ký Sudo trên Journald (với lệnh [journalctl]) hoặc Rsyslogd (trong [/ var/log/secure] file ), nhưng nếu bạn chỉ muốn giữ nhật ký Sudo trong một tệp khác, hãy định cấu hình như sau.
[root@dlp ~]#
visudo
# add to the end
# for example, output logs to [local1] facility

Defaults syslog=local1
[root@dlp ~]#
vi /etc/rsyslog.conf
# line 47,48 : add like follows

*.info;mail.none;authpriv.none;cron.none;local1.none   /var/log/messages
local1.*                /var/log/sudo.log

# The authpriv file has restricted access.
authpriv.*              /var/log/secure

[root@dlp ~]#
systemctl restart rsyslog