Linux "visudo" Command Line Options and Examples
edit the sudoers file

visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors. If the sudoers file is currently being edited you will receive a message to try again later.


Usage:

visudo [-chqsV] [-f sudoers] [-x output_file]






Command Line Options:

-c
Enable check-only mode. The existing sudoers file will be checked for syntax errors, owner andmode. A message will be printed to the standard output describing the status of sudoers unless the
visudo -c ...
-q
If an error is encountered, visudo will exit with a value of 1.
visudo -q ...
-f
Specify an alternate sudoers file location. With this option, visudo will edit (or check) thesudoers file of your choice, instead of the default, /etc/sudoers. The lock file used is the speci‐fied sudoers file with “.tmp” appended to it. In check-only mode only, the argument to -f may be
visudo -f ...
-’
indicating that sudoers will be read from the standard input.
visudo -’ ...
-h
--help Display a short help message to the standard output and exit.
visudo -h ...
-s
Enable strict checking of the sudoers file. If an alias is referenced but not actually defined orif there is a cycle in an alias, visudo will consider this a parse error. Note that it is not pos‐sible to differentiate between an alias and a host name or user name that consists solely of upper‐case letters, digits, and the underscore (‘_’) character.
visudo -s ...
-V
Print the visudo and sudoers grammar versions and exit.
visudo -V ...
-x
Export a sudoers in JSON format and write it to output_file. If output_file is ‘-’, the exportedsudoers policy will be written to the standard output. By default, /etc/sudoers (and any files itincludes) will be exported. The -f option can be used to specify a different sudoers file toexport. The exported format is intended to be easier for third-party applications to parse than thetraditional sudoers format. The various values have explicit types which removes much of the ambi‐guity of the sudoers format.Debugging and sudoers plugin argumentsvisudo versions 1.8.4 and higher support a flexible debugging framework that is configured via Debug lines inthe sudo.conf(5) file.Starting with sudo 1.8.12, visudo will also parse the arguments to the sudoers plugin to override the defaultsudoers path name, UID, GID and file mode. These arguments, if present, should be listed after the path to theplugin (i.e. after sudoers.so). Multiple arguments may be specified, separated by white space. For example:Plugin sudoers_policy sudoers.so sudoers_mode=0400The following arguments are supported:sudoers_file=pathnameThe sudoers_file argument can be used to override the default path to the sudoers file.sudoers_uid=uidThe sudoers_uid argument can be used to override the default owner of the sudoers file. It should bespecified as a numeric user ID.sudoers_gid=gidThe sudoers_gid argument can be used to override the default group of the sudoers file. It must bespecified as a numeric group ID (not a group name).sudoers_mode=modeThe sudoers_mode argument can be used to override the default file mode for the sudoers file. Itshould be specified as an octal value.For more information on configuring sudo.conf(5), please refer to its manual.ENVIRONMENTThe following environment variables may be consulted depending on the value of the editor and env_editor sudoerssettings:VISUAL Invoked by visudo as the editor to useEDITOR Used by visudo if VISUAL is not setFILES/etc/sudo.conf Sudo front end configuration/etc/sudoers List of who can run what/etc/sudoers.tmp Lock file for visudoDIAGNOSTICSIn addition to reporting sudoers parse errors, visudo may produce the following messages:sudoers file busy, try again later.Someone else is currently editing the sudoers file./etc/sudoers.tmp: Permission deniedYou didn't run visudo as root.you do not exist in the passwd databaseYour user ID does not appear in the system passwd database.Warning: {User,Runas,Host,Cmnd}_Alias referenced but not definedEither you are trying to use an undeclared {User,Runas,Host,Cmnd}_Alias or you have a user or host namelisted that consists solely of uppercase letters, digits, and the underscore (‘_’) character. In the lat‐ter case, you can ignore the warnings (sudo will not complain). The message is prefixed with the pathname of the sudoers file and the line number where the undefined alias was used. In -s (strict) modethese are errors, not warnings.Warning: unused {User,Runas,Host,Cmnd}_AliasThe specified {User,Runas,Host,Cmnd}_Alias was defined but never used. The message is prefixed with thepath name of the sudoers file and the line number where the unused alias was defined. You may wish tocomment out or remove the unused alias.Warning: cycle in {User,Runas,Host,Cmnd}_AliasThe specified {User,Runas,Host,Cmnd}_Alias includes a reference to itself, either directly or through analias it includes. The message is prefixed with the path name of the sudoers file and the line numberwhere the cycle was detected. This is only a warning unless visudo is run in -s (strict) mode as sudowill ignore cycles when parsing the sudoers file.unknown defaults entry "name"The sudoers file contains a Defaults setting not recognized by visudo./etc/sudoers: input and output files must be differentThe -x flag was used and the specified output_file has the same path name as the sudoers file to export.
visudo -x ...