Pcornel
Linux · Users & Groups

sudoers

Cheat sheet · https://pcornel.dk/topic.php?topic=2704

Back to the Topic

Answer

sudoers (/etc/sudoers and /etc/sudoers.d/) defines who may run which commands as which user with sudo, e.g. %admins ALL=(ALL) ALL.

Remember

Always edit with visudo (or visudo -f /etc/sudoers.d/<file>) — a syntax error can lock everyone out of sudo. Prefer group rules over individual users. Avoid NOPASSWD for broad rules, and avoid allowing editors or shells that let users escape to root.

First checks

  • visudo -c — syntax check of all sudoers files
  • id <user> — UID, primary group and groups
  • getent passwd <user> — account entry (local or directory)
  • getent group <group> — group members
  • sudo -l -U <user> — what the user may run with sudo

Commands

sudo

Verify in this order

user runs sudo → rules matched (user/group, host, target user, command) → password if required → command runs and is logged

Where it usually breaks

First mismatch in identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2704

Confirmation

Confirm action

Continue?