Free Tool

Will This Sudoers File Lock You Out?

Paste the file. The checker reads it the way visudo does and reports every line visudo would reject, plus the traps visudo accepts but you should not ship. It runs entirely in your browser, so nothing you paste leaves the page.

One syntax error in /etc/sudoers and sudo refuses to run at all, which locks every account out of admin access until the file is fixed from a root shell or recovery. Check the file before it goes near the machine.

Check your sudoers file

Paste a sudoers file or a sudoers.d drop-in below. The checker reads it in your browser, reports every line visudo would reject, and flags the traps visudo accepts but you should not ship.

What the checker looks for

The checker judges the text against the sudoers grammar in the sudo manual (version 1.8.31).

Line shape. A user specification is written user host = command, command, .... A line with no = is a syntax error, and so is a line with a user but no host before the =. Long lines may continue with a backslash as the last character.

Tags. The tags sudo understands are EXEC, NOEXEC, FOLLOW, NOFOLLOW, LOG_INPUT, NOLOG_INPUT, LOG_OUTPUT, NOLOG_OUTPUT, MAIL, NOMAIL, PASSWD, NOPASSWD, SETENV and NOSETENV. A tag always needs a colon after it. NOPASSWD /usr/bin/id is a syntax error; NOPASSWD: /usr/bin/id is the rule. Any other word followed by a colon is an unknown tag and the file is rejected.

Runas. The part in parentheses after the = says who the command runs as: (ALL), (root), (root:adm) or (:group). An unbalanced parenthesis is a syntax error.

Command paths must be absolute. A bare command name is a syntax error, and visudo says so plainly: expected a fully-qualified path name. Write /usr/bin/systemctl, not systemctl. The built-in ALL is the only bare word allowed, and sudoedit needs an absolute path to the file it may edit.

Aliases. The four alias kinds are User_Alias, Runas_Alias, Host_Alias and Cmnd_Alias, and an alias name must be upper-case letters, digits and underscore, starting with a letter. A lowercase alias name is a syntax error. A command alias that is used but never defined draws a warning here, the same warning visudo prints; in strict mode (visudo -s) it is an error instead.

Defaults. The checker knows the 70 Defaults parameters visudo 1.9.15p5 recognizes. An unknown one is an error, exactly as visudo reports it (unknown defaults entry). Parameters that need a value are flagged when given bare, and values for the path parameters (editor, env_file, mailerpath, lecture_file, logfile, timestampdir) must start with /.

Include directives. #include and #includedir take a file or directory path; @include and @includedir are the newer forms and mean the same thing. Files pulled in by an includedir are read in sorted lexical order, so use a consistent number of leading zeroes: 01_first loads before 10_second, but 1_whoops loads after 10_second. There is a hard limit of 128 nested include files.

Drop-in file names. sudo silently ignores files in a #includedir directory whose names end in ~ or .bak, or contain a . character. A file called 10-deploy.bak or 10-deploy~ is never read, and nothing warns you. Type the file name into the box above and the checker flags it.

Dangerous patterns (warnings, not errors). NOPASSWD: ALL lets a user run every command as root without a password. A wildcard in a command path matches more than the one command written. Negation (!) on a command is warned about because the manual says so: "all but a few" rules rarely work as intended, since a user who can run everything except one command can usually reach that command another way.

Two things visudo does not require

Two assumptions did not survive the test corpus, and the checker does not enforce them.

First, a missing trailing newline is fine. A file whose last line has no newline parses cleanly. The checker does not flag it.

Second, an alias may be used before it is defined. A file that uses RESTART on line 1 and defines Cmnd_Alias RESTART on line 2 parses cleanly, even in strict mode. Only an alias that is never defined anywhere in the file is warned about.

Example files and visudo's verdicts

Six files were rejected, four parsed with warnings only, and ten parsed clean.

Mistake What visudo says
Tag with no colon (NOPASSWD /usr/bin/id) syntax error
Bare command name (systemctl) expected a fully-qualified path name
Unknown tag (FOO:) syntax error
No = in a user specification syntax error
Unknown Defaults entry (frobnicate) unknown defaults entry "frobnicate"
Lowercase alias name (admins) syntax error

The four warning-only files were an undefined command alias, a negated command, a wildcard in a command path, and NOPASSWD: ALL. All four parse under visudo, and all four are things the checker flags anyway. Of 72 candidate names, only the two planted controls came back unknown.

Install it safely

  1. Check the copy first. Run visudo -cf /path/to/copy on the file you pasted. It checks syntax only and exits 0 on success, 1 on error. You can also pipe a file through it: visudo -cf - < file.
  2. Check the real file too. Run visudo -c on the installed file. That is the check that also verifies ownership and permissions: the file must be owned by root and set to mode 0440, and must not be world-writable.
  3. Never edit /etc/sudoers directly. Use visudo, which locks the file against simultaneous edits and refuses to install a file with a syntax error. If you are adding a rule, prefer a drop-in under /etc/sudoers.d with a name that contains no dot and does not end in ~ or .bak, mode 0440, owned by root.
  4. Test the rule before you depend on it. Run sudo -l -U username to see what the user may actually run, and try the command in a second terminal while your current root session is still open.

Frequently asked questions

Does this page send my sudoers file anywhere? No. The checker is client-side JavaScript. Your paste stays in your browser tab and is never uploaded, logged, or sent to any server.

Is this page a replacement for visudo? No. It checks the syntax of the pasted text only. It cannot check the file mode, the owner, or the contents of files pulled in by #include. Run visudo -c on the real file for those checks.

What does visudo check that this page cannot? Ownership and permissions: a sudoers file must be owned by root and set to mode 0440, and must not be world-writable. visudo -c on the real file checks those; visudo -cf on a copy checks syntax only.

Why does the checker warn about NOPASSWD: ALL? Because visudo accepts it and it means passwordless root for every command on the machine. A rule that grants one job should name that one job, not ALL.

My drop-in file is ignored. What went wrong? Check the file name first. sudo silently ignores files in a #includedir directory whose names contain a dot or end in ~ or .bak, so a file called 10-deploy.bak or 10-deploy~ is never read. Files are also read in sorted lexical order, so 1_whoops loads after 10_second.

Does a missing trailing newline break the file? No. visudo parses a file whose last line has no trailing newline. The checker does not flag it.

Sources

  • sudo, sudoers manual (version 1.8.31) — the file format, the 14 command tags, the four alias kinds, the include directives and the silently-skipped file names, the negation warning, and the 0440 mode and root ownership rules.
  • visudo(8) — Linux manual page — check-only mode (-c, exit 0 or 1), -f for a copy (syntax only, no ownership or mode check), strict mode (-s, undefined aliases become errors), and the undefined-alias, unused-alias and cycle warnings.

Keep Exploring