su -sudovisudosudo -l| su | sudo | |
|---|---|---|
| Requires | The TARGET user's password | YOUR OWN password (by default) |
| Scope | Opens a full shell as another user | Runs one command with elevated privileges, then returns |
| Logging | Minimal | Every invocation logged to /var/log/secure |
| Granularity | All-or-nothing | Can be restricted to specific commands per user/group |
# Switch to root, requires ROOT's password, starts a login shell su - # Run a single command as root, requires YOUR OWN password sudo systemctl restart sshd # Get an interactive root shell via sudo instead sudo -i
# ALWAYS edit sudo configuration with visudo — never a plain editor sudo visudo # Grant a specific user full sudo access sarah ALL=(ALL) ALL # Grant a user sudo access to only specific commands miguel ALL=(ALL) /usr/bin/systemctl restart httpd, /usr/bin/systemctl status httpd # Allow a command WITHOUT prompting for a password miguel ALL=(ALL) NOPASSWD: /usr/bin/systemctl status httpd
Rule format: who host=(run as) commands
# Prefer a dedicated file per admin/team over editing the main file
sudo visudo -f /etc/sudoers.d/miguel
/etc/sudoers.d/ whose names contain a dot or end in ~, so name them simply, like miguel.# In /etc/sudoers, this line is often present (may need uncommenting): %wheel ALL=(ALL) ALL # Add a user to the wheel group to grant them full sudo access sudo usermod -aG wheel sarah # Confirm membership groups sarah
%wheel rule is active by default. Group membership scales better than individual entries; the user must log in again for it to take effect.# Show what commands YOU are currently allowed to run with sudo sudo -l # Review the sudo activity log sudo grep sudo /var/log/secure # Or, if using the journal exclusively journalctl _COMM=sudo
sudo -l is the fastest way to confirm a sudoers change did what you intended.No root password and no sudo access? Use the Chapter 12 boot-time procedure:
rd.break to the linux linemount -o remount,rw /sysroot, then chroot /sysrootpasswd roottouch /.autorelabel on SELinux systemsIf a sudoers syntax error blocks sudo but root's password still works, you don't need the boot-time procedure.
su -, and fix the file with visudo.wheel group for team-wide accessvisudosudo -l and the audit logssu require, and whose does sudo require?su?visudo?wheel group?