visudo
Linux · Users and permissions · reference only
What it does
Edits /etc/sudoers by locking it and checking the syntax before saving, so sudo is not left unusable.
Syntax
visudo [opciones]
Options and parameters
-cOnly checks the sudoers syntax and exits.
-f ficheroEdits or checks another file, such as one in /etc/sudoers.d/.
-sStrict mode: treats any alias used without being defined as an error.
-qQuiet mode: prints fewer messages when checking.
-VShows the version and the sudoers configuration.
Usage examples
sudo visudoOpens /etc/sudoers in the editor and validates on save.
sudo visudo -cChecks the syntax of the current configuration.
sudo visudo -f /etc/sudoers.d/devsCreates or edits your own rule without touching the main file.
sudo visudo -cf /etc/sudoers.d/devsChecks only that rules file.
Notes and common mistakes
- It uses the editor set in EDITOR or VISUAL.
- For rules about one group or user it is cleaner to use files in /etc/sudoers.d/.
- A badly written sudoers line can lock you out of sudo: never edit it with a plain editor.