sudo, su and Policy Validation
Quick answer
Use delegated privilege only for an authorized task. sudo and su are different mechanisms; a valid policy file is not proof of safe authorization. Learn syntax on a harmless sample instead of editing the real policy.
Prepare the practice environment
Use the chapter fixture described in lab-fixtures/users/README.md. Run setup as a normal user in a disposable Linux environment, enter the printed directory, check pwd, and run export LC_ALL=C; umask 022. Every local example assumes a fresh fixture; examples explicitly marked VM ONLY require an authorized snapshot-backed VM and must not be run in the ordinary fixture. Commands omit the terminal prompt; outputs below are not commands.
How it works
sudo asks an authorization policy whether a command may run as a target identity; the usual default target is root, but configuration can differ. sudo -l lists permitted commands subject to policy and authentication. su USER starts a shell or command under another identity, subject to authentication and account restrictions; su - USER requests a login-style environment. visudo coordinates edits and checks syntax. A sudoers rule has a subject, host, run-as identity and command specification. This chapter uses a fictional rule permitting only /usr/bin/id as nobody, not a real grant. Syntax checks do not evaluate all security consequences, installed paths or external policy.
Read the fictional rule as four questions: who may request access, on which host, as which target identity, and to which command. The sample names /usr/bin/id; its absence of an argument restriction means it does not limit that command to one specific argument list. A successful visudo syntax check on the private sample does not install it or grant permission. Real policy review must also consider included files, other matching rules, the command behavior and the actual target environment.
Try the examples
The subject is bm9learner, the host specification is ALL, the target is nobody, and the command path is /usr/bin/id. No argument restriction is specified. The file is not installed.
Expected stdout:
bm9learner ALL=(nobody) /usr/bin/idvisudo -c -q -f sudoers.sample && printf 'syntax accepted\n'This checks only the standalone file; no privileged command or real sudoers edit occurs. If visudo is absent or local policy disallows reading, leave this example untested.
Expected stdout:
syntax accepted# VM ONLY: run only with instructor authorizationsudo -lThe list depends on policy and may require authentication. Do not share it publicly. This does not install the sample rule or demonstrate that it grants access.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Do not edit /etc/sudoers directly, grant unrestricted ALL commands, disable authentication, or install the sample rule. Real policy changes need authorization, review and a tested recovery path.
Practice
Label the four parts of sudoers.sample. Compare sudo -u nobody /usr/bin/id conceptually with su - nobody; explain why neither should be executed without authorization and why a valid file can still overgrant.
Related references
Study: sudo, su, visudo. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
sudo, su and policy validation — Knowledge Check
Apply the lesson concepts to the controlled account fixture.
What is the role of sudo policy?
Which tool checks a standalone sudoers file?
What does a successful syntax check prove?
What does su - USER request?