sudoers — Delegated administrative policy
The sudoers policy plugin interprets /etc/sudoers and included files, often /etc/sudoers.d. Rules constrain who can execute which command on which host and as which identity. An omitted argument constraint can allow arbitrary arguments; a command with explicit empty argument string permits no arguments. Avoid broad wildcards, unrestricted shells or writable command paths. Defaults are scope-sensitive; later matching settings of the same scope generally override earlier ones, and matching command rules are order-sensitive. Authentication and timestamp defaults vary by policy. Edit through visudo in a recoverable administrative session; validate the entire policy including includes before committing. Syntax alone cannot establish least privilege. Sudo evaluates policy at invocation; existing shells and credentials are not retroactively revoked. Restore the prior validated policy using a recovery console if necessary. The example only checks a private Defaults line; no sudo execution or policy installation.
Formal Syntax & Structure
Defaults OPTIONUSER HOST=(RUNAS) COMMAND [ARGS]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| Defaults | directive | Policy options |
| USER | directive | Authorized identity or group |
| HOST | directive | Host match |
| RUNAS | directive | Target identity |
| COMMAND | directive | Allowed command and argument constraints |
Return Value
Policy parse success does not establish authorization safety.
Working Example
set -eud=$(mktemp -d)trap 'rm -rf -- "$d"' EXITprintf 'Defaults env_reset\n' > "$d/sudoers"chmod 0440 "$d/sudoers"visudo -c -f "$d/sudoers" > "$d/check"grep -F 'parsed OK' "$d/check" >/dev/nullprintf 'private sudoers syntax accepted\n'