Home·Terminal commands

visudo

Permissions

Usage

sudo visudo

Edits /etc/sudoers with a lock and a syntax check before saving; editing that file directly and getting it wrong locks everyone out of sudo, which is exactly what visudo prevents.

Common flags

FlagMeaning
-cCheck the syntax of the current file and exit
-fEdit another sudoers file, such as one under /etc/sudoers.d
-sCheck strictly, refusing anything questionable
EDITOR=Set it in front to choose the editor, as in EDITOR=nano

Examples

sudo visudo -c

Checks sudoers for syntax errors.

sudo visudo -f /etc/sudoers.d/deploy

Edits a drop-in file rather than the main one.

sudo EDITOR=nano visudo

Uses nano instead of vi.

Numeric and symbolic modes name the same thing: 755 and u=rwx,go=rx are the same permission.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does visudo do?

Edits /etc/sudoers with a lock and a syntax check before saving; editing that file directly and getting it wrong locks everyone out of sudo, which is exactly what visudo prevents.

Q. How do I type it?

sudo visudo — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

4 are listed here; the full set is in man visudo. This command sits under Permissions.

Related commands

man page: man visudo