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

  • -c

    Only checks the sudoers syntax and exits.

  • -f fichero

    Edits or checks another file, such as one in /etc/sudoers.d/.

  • -s

    Strict mode: treats any alias used without being defined as an error.

  • -q

    Quiet mode: prints fewer messages when checking.

  • -V

    Shows the version and the sudoers configuration.

Usage examples

  • sudo visudo

    Opens /etc/sudoers in the editor and validates on save.

  • sudo visudo -c

    Checks the syntax of the current configuration.

  • sudo visudo -f /etc/sudoers.d/devs

    Creates or edits your own rule without touching the main file.

  • sudo visudo -cf /etc/sudoers.d/devs

    Checks 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.

Related commands