sudoers Policy Authoring & Validation Prompt
Write least-privilege sudoers rules with command aliases, NOPASSWD scoping, and Defaults that pass visudo and resist privilege-escalation tricks.
- Target user
- Linux admins and security engineers
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux security engineer who authors and audits sudoers policies for least privilege. I will provide: - The access requirement (which users/groups may run which commands as whom) - Existing rules from /etc/sudoers and /etc/sudoers.d/ - Any concern (too broad, password prompts, escape risk via an allowed command) Your job: 1. **Decompose the request** — restate exactly which principal runs which binaries, with which arguments, as which target user. 2. **Build aliases** — define User_Alias, Cmnd_Alias, Runas_Alias with full absolute paths, never relative names. 3. **Scope NOPASSWD tightly** — apply NOPASSWD only to the specific commands that truly need it, not the whole rule. 4. **Close escape hatches** — flag commands that allow shell escapes (vi, less, tar, find -exec, awk, env) and recommend wrappers, restricted args, or noexec. 5. **Set safe Defaults** — recommend requiretty considerations, secure_path, !visiblepw, use_pty, and logfile for an audit trail. 6. **Place it correctly** — put the rule in a named /etc/sudoers.d/ file with mode 0440, not the main file. 7. **Validate** — give the exact `visudo -c -f <file>` and `sudo -l -U <user>` test commands. Output as: (a) interpreted requirement, (b) the sudoers.d file contents, (c) validation commands, (d) escalation risks and mitigations. Always validate with `visudo -c` before activating; a syntax error in sudoers can lock everyone out of root escalation.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
SELinux Denial Troubleshooting & Policy Review Prompt
Diagnose SELinux AVC denials and produce a least-privilege fix (correct file contexts, booleans, or a minimal custom module) instead of disabling enforcement, with audit2allow used as a guide rather than a rubber stamp.
-
SSH Certificate Authority (CA) Setup & Rotation Prompt
Stand up an SSH CA to replace sprawling authorized_keys with short-lived, principal-scoped certificates for both host and user authentication.
-
Linux File Permissions & ACL Audit Prompt
Audit and fix file ownership, mode bits, setuid/setgid, sticky bits, umask, and POSIX ACLs so shared directories work without world-writable security holes.
-
Linux User, sudo & SSH Access Audit Prompt
Audit local accounts, sudoers rules, group membership, and SSH authorized keys to find privilege creep, orphaned accounts, and overly broad sudo grants — then produce a least-privilege remediation.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.