Edit /etc/sudoers and check syntax before saving.
Do not overwrite the file directly with an ordinary text editor.
Which command is appropriate?
visudo locks sudoers during editing and parses it before saving, reducing the risk of losing administrative access through a syntax error.
Detailed explanation
visudoCorrect. It edits sudoers with locking and syntax validation.
Correct. It edits sudoers with locking and syntax validation.
sudo -lIncorrect. sudo -l lists privileges for the current user.
Incorrect. sudo -l lists privileges for the current user.
su /etc/sudoersIncorrect. su changes user context and is not a sudoers editor.
Incorrect. su changes user context and is not a sudoers editor.
passwd /etc/sudoersIncorrect. passwd manages user passwords, not sudoers.
Incorrect. passwd manages user passwords, not sudoers.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' 'visudo -> lock, edit, syntax-check sudoers'Expected result
visudo -> lock, edit, syntax-check sudoersKey points
- Use visudo
- Check syntax
- Lock concurrent edits
Notes
- Environment: sudo visudoの動作対応表(file編集なし)
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.