visudo
Overview
visudo safely edits the /etc/sudoers file. It locks the file against simultaneous edits and performs syntax checking before saving to prevent accidental lockout.
Syntax
visudo [options]Common Options
| Option | Description |
|---|---|
-c, --check |
Check syntax of sudoers file without editing |
-f, --file FILE |
Edit or check specified file instead of default /etc/sudoers |
-s, --strict |
Enable strict syntax checking |
Key Use Cases
- Safely modifying administrative permissions in
/etc/sudoers. - Validating custom sudo configuration files in
/etc/sudoers.d/.
Examples with Explanations
Example 1: Check Sudoers Syntax
visudo -cParses /etc/sudoers and validates syntax without opening an editor.