Use it to grant or limit administrative rights, or when sudo refuses a user.
sudoers
sudoers (/etc/sudoers and /etc/sudoers.d/) defines who may run which commands as which user with sudo, e.g. %admins ALL=(ALL) ALL.
1. sudo -l -U <user> — what may they run?
2. Not allowed → member of the admin group (sudo/wheel)? New login?
3. Add a rule with visudo -f /etc/sudoers.d/<name>.
4. Syntax check: visudo -c.
5. Test: sudo -u <user> sudo -l or log in as the user.
user runs sudo → rules matched (user/group, host, target user, command) → password if required → command runs and is logged
For Users & Groups → sudoers, continue with the first unproven Topic check: Identify invoking user/groups, host context, requested target identity and exact command path/arguments. If that boundary is healthy, advance to the adjacent check: Validate the effective sudoers policy including included files before applying changes. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
invoking process identity → sudo policy sources/includes → rule match → authentication/options/environment → target UID/GID transition → command execution → target/workload result
Healthy evidence: the minimum required rule matches only the intended invocation, resulting credentials are correct and the original administrative operation succeeds without broader privilege than needed.
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Identify invoking user/groups, host context, requested target identity and exact command path/arguments.
- Validate the effective sudoers policy including included files before applying changes.
- Confirm the rule actually matched and capture the resulting effective UID/GID/environment.
- Verify the target command and workload result separately under the delegated identity.
Verification chain. invoking process identity → sudo policy sources/includes → rule match → authentication/options/environment → target UID/GID transition → command execution → target/workload result
Step 3 Commands Verify boundary
visudo
visudo -c
sudo -l -U alice
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: sudo login/authentication is confused with policy authorization, wildcard rules overmatch, or root-command success is treated as evidence the normal service identity is fixed.
Step 5 Common mistakes Narrow the fault
- Editing
/etc/sudoerswithoutvisudoand breaking sudo.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
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.
visudo -c— syntax check of all sudoers filesid <user>— UID, primary group and groupsgetent passwd <user>— account entry (local or directory)getent group <group>— group memberssudo -l -U <user>— what the user may run with sudo
ReferenceWhat it is1 section · depth on demand
Core model
Trace the invoking identity, matched sudoers rule and effective target identity before evaluating the command itself. Consider include files, aliases, rule ordering/precedence semantics, command path/arguments where applicable and environment restrictions. A sudo policy match shows delegated authorization for the matched invocation, not that the target command is safe, correct or successful.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
A sudoers rule shows intended delegation only when it matches the exact invocation, but it does not show command safety, non-DAC policy, target state or workload success.
sudoers owns sudo authorization policy.
In depth
sudoers rules and safe administration
sudo lets users run commands as root, or as another user, according to rules in /etc/sudoers and its include directory. The sudoers manual describes rule syntax as "who where = (as_whom) what".
- Groups are written with
%. - Aliases (User_Alias, Runas_Alias, Host_Alias, Cmnd_Alias) group names and commands.
NOPASSWD:skips the password prompt for the commands that follow.- When several entries match, the last match wins, which isn't necessarily the most specific one.
@includedir /etc/sudoers.dreads all files there in sorted order, but skips files that end in~or contain a dot.
Rule examples
| Rule | Meaning |
|---|---|
%sudo ALL=(ALL:ALL) ALL | Members of sudo may run anything, with their password |
alice ALL=(root) /usr/bin/systemctl restart nginx | One specific command |
%webops ALL=(root) NOPASSWD: /usr/bin/systemctl reload nginx | No password for one command |
deploy ALL=(appuser) NOPASSWD: /opt/app/bin/deploy | Run as appuser, not root |
Cmnd_Alias LOGS = /usr/bin/journalctl, /usr/bin/tail -f /var/log/* | An alias for reuse |
Defaults worth knowing (manual)
| Default | Behaviour |
|---|---|
env_reset | On: commands run with a minimal environment |
secure_path | Sets PATH for commands run through sudo |
timestamp_timeout | 5 minutes of cached credentials |
| Logging | To syslog by default |
Pitfalls
| Pitfall | Why |
|---|---|
| Wildcards in arguments | The manual warns they need care; tail -f /var/log/* also matches /var/log/../../etc/shadow |
Allowing editors, shells, less or find | They can start a root shell; use sudoedit for file editing |
A file in sudoers.d named app.conf | Ignored, because the name contains a dot |
Editing without visudo | A syntax error can lock everyone out of sudo |
host$ sudo visudo -f /etc/sudoers.d/webops
%webops ALL=(root) NOPASSWD: /usr/bin/systemctl reload nginx, /usr/bin/systemctl status nginx
host$ sudo visudo -c
/etc/sudoers: parsed OK
/etc/sudoers.d/webops: parsed OK
host$ sudo -l -U bob
host$ sudoedit /etc/nginx/sites-available/default
host$ sudo journalctl _COMM=sudo -n 3 --no-pager
sudoedit instead of sudo vi
sudoedit copies the file, opens it in the user's own editor without privileges, and writes it back as root. The editor never runs as root, so it can't be used to escape into a root shell.
Documented example, not captured output.
How it works at runtime
sudoers is part of Users & Groups → sudoers. sudoers is the policy model used by sudo to decide which invoking principals may run which commands as which target users/groups under defined host, authentication, environment and option constraints; policy authorization is distinct from the executed command result.
Topic-specific state model. sudoers is the policy model used by sudo to decide which invoking principals may run which commands as which target users/groups under defined host, authentication, environment and option constraints; policy authorization is distinct from the executed command result.
Interpretation rule. - sudo authentication success ≠ sudoers authorization.
- sudoers authorization ≠ command/workload success.
- Broad command path or wildcard policy ≠ least privilege.
- Policy file edit ≠ syntax-valid/effective policy until parsed and matched in the real context.
Quick reference
sudoers grants commands to users and groups. Always edit with visudo (syntax check) and prefer drop-in files in /etc/sudoers.d/.
# /etc/sudoers.d/ops (mode 0440)
%ops ALL=(ALL) ALL
Defaults:%ops timestamp_timeout=5
backup ALL=(root) NOPASSWD: /usr/bin/systemctl restart backup-agent, /usr/bin/rsync
Defaults logfile=/var/log/sudo.log, log_input, log_output
visudo -cf /etc/sudoers.d/ops
sudo -l -U alice
sudoreplay -l
Avoid allowing editors, shells, less, find, tar or interpreters via NOPASSWD — they can spawn root shells (see GTFOBins). Grant specific commands with fixed arguments.
Limits and how it fails
Primary failure point. A sudoers rule shows intended delegation only when it matches the exact invocation, but it does not show command safety, non-DAC policy, target state or workload success.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Configuration intent and lifecycle. Treat /etc/passwd, /etc/shadow, /etc/group and sudoers as policy databases with strict syntax, ownership and permission requirements, while remembering that NSS can source identities elsewhere.
Distribution/platform context. sudoers owns sudo authorization policy. Users & Groups owns source identities; root/UID/GID owns resulting identities; application-specific privilege design remains elsewhere.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Users & Groups → sudoers. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.kernel.org/doc/man-pages/ · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
sudoers operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for sudoers.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | sudoers is the policy model used by sudo to decide which invoking principals may run which commands as which target users/groups under defined host, authentication, environment and option constraints; policy authorization is distinct from the executed command result. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin the exact process/session → resolve user/group names to numeric UID/GID through the effective identity stack → capture effective UID/GID + supplementary groups → resolve every required path component and target inode → inspect numeric owner/group + mode + ACL/mask + special bits → capture sudo/privilege transition if present → account for non-DAC controls → repeat the original workload operation. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | invoking process identity → sudo policy sources/includes → rule match → authentication/options/environment → target UID/GID transition → command execution → target/workload result | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | A sudoers rule proves intended delegation only when it matches the exact invocation; it does not prove command safety, non-DAC policy, target state or workload success. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux identity and authorization evidence can establish this proof path: invoking process identity → sudo policy sources/includes → rule match → authentication/options/environment → target UID/GID transition → command execution → target/workload result | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured identity source, process credential, filesystem object, DAC/ACL, privilege or workload scope. A sudoers rule proves intended delegation only when it matches the exact invocation; it does not prove command safety, non-DAC policy, target state or workload success. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: keep the same process/session, resolve numeric identity and groups, inspect each path component plus target ownership/mode/ACL/special bits, capture any privilege transition/non-DAC denial, then repeat the original operation before broadening permissions. | Continue to the next unresolved boundary while preserving the original test condition. |
sudoers · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | sudoers |
|---|---|
| Topic path | Users & Groups → sudoers |
| Runtime state | sudoers is the policy model used by sudo to decide which invoking principals may run which commands as which target users/groups under defined host, authentication, environment and option constraints; policy authorization is distinct from the executed command result. |
| Fast checks | - Identify invoking user/groups, host context, requested target identity and exact command path/arguments. - Validate the effective sudoers policy including included files before applying changes. - Confirm the rule actually matched and capture the resulting effective UID/GID/environment. - Verify the target command and workload result separately under the delegated identity. |
| Verification chain | invoking process identity → sudo policy sources/includes → rule match → authentication/options/environment → target UID/GID transition → command execution → target/workload result Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | A sudoers rule proves intended delegation only when it matches the exact invocation; it does not prove command safety, non-DAC policy, target state or workload success. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |