1VISUDO(8)                 BSD System Manager's Manual                VISUDO(8)
2

NAME

4     visudo — edit the sudoers file
5

SYNOPSIS

7     visudo [-chIOPqsV] [[-f] sudoers]
8

DESCRIPTION

10     visudo edits the sudoers file in a safe fashion, analogous to vipw(8).
11     visudo locks the sudoers file against multiple simultaneous edits, per‐
12     forms basic validity checks, and checks for syntax errors before in‐
13     stalling the edited file.  If the sudoers file is currently being edited
14     you will receive a message to try again later.
15
16     visudo parses the sudoers file after editing and will not save the
17     changes if there is a syntax error.  Upon finding an error, visudo will
18     print a message stating the line number(s) where the error occurred and
19     the user will receive the “What now?” prompt.  At this point the user may
20     enter ‘e’ to re-edit the sudoers file, ‘x’ to exit without saving the
21     changes, or ‘Q’ to quit and save changes.  The ‘Q’ option should be used
22     with extreme caution because if visudo believes there to be a syntax er‐
23     ror, so will sudo.  If ‘e’ is typed to edit the sudoers file after a syn‐
24     tax error has been detected, the cursor will be placed on the line where
25     the error occurred (if the editor supports this feature).
26
27     There are two sudoers settings that determine which editor visudo will
28     run.
29
30     editor    A colon (‘:’) separated list of editors allowed to be used with
31               visudo.  visudo will choose the editor that matches the user's
32               SUDO_EDITOR, VISUAL, or EDITOR environment variable if possi‐
33               ble, or the first editor in the list that exists and is exe‐
34               cutable.  sudo does not preserve the SUDO_EDITOR, VISUAL, or
35               EDITOR environment variables unless they are present in the
36               env_keep list or the env_reset option is disabled in the
37               sudoers file.  The default editor path is
38               /usr/bin/nano:/usr/bin/vim:/usr/bin/vi which can be set at com‐
39               pile time via the --with-editor configure option.
40
41     env_editor
42               If set, visudo will use the value of the SUDO_EDITOR, VISUAL,
43               or EDITOR environment variables before falling back on the de‐
44               fault editor list.  visudo is typically run as root so this op‐
45               tion may allow a user with visudo privileges to run arbitrary
46               commands as root without logging.  An alternative is to place a
47               colon-separated list of “safe” editors in the editor variable.
48               visudo will then only use SUDO_EDITOR, VISUAL, or EDITOR if
49               they match a value specified in editor.  If the env_reset flag
50               is enabled, the SUDO_EDITOR, VISUAL, and/or EDITOR environment
51               variables must be present in the env_keep list for the
52               env_editor flag to function when visudo is invoked via sudo.
53               The default value is on, which can be set at compile time via
54               the --with-env-editor configure option.
55
56     The options are as follows:
57
58     -c, --check
59                 Enable check-only mode.  The existing sudoers file (and any
60                 other files it includes) will be checked for syntax errors.
61                 If the path to the sudoers file was not specified, visudo
62                 will also check the file ownership and permissions (see the
63                 -O and -P options).  A message will be printed to the stan‐
64                 dard output describing the status of sudoers unless the -q
65                 option was specified.  If the check completes successfully,
66                 visudo will exit with a value of 0.  If an error is encoun‐
67                 tered, visudo will exit with a value of 1.
68
69     -f sudoers, --file=sudoers
70                 Specify an alternate sudoers file location, see below.  As of
71                 version 1.8.27, the sudoers path can be specified without us‐
72                 ing the -f option.
73
74     -h, --help  Display a short help message to the standard output and exit.
75
76     -I, --no-includes
77                 Disable the editing of include files unless there is a pre-
78                 existing syntax error.  By default, visudo will edit the main
79                 sudoers file and any files included via @include or #include
80                 directives.  Files included via @includedir or #includedir
81                 are never edited unless they contain a syntax error.
82
83     -O, --owner
84                 Enforce the default ownership (user and group) of the sudoers
85                 file.  In edit mode, the owner of the edited file will be set
86                 to the default.  In check mode (-c), an error will be re‐
87                 ported if the owner is incorrect.  This option is enabled by
88                 default if the sudoers file was not specified.
89
90     -P, --perms
91                 Enforce the default permissions (mode) of the sudoers file.
92                 In edit mode, the permissions of the edited file will be set
93                 to the default.  In check mode (-c), an error will be re‐
94                 ported if the file permissions are incorrect.  This option is
95                 enabled by default if the sudoers file was not specified.
96
97     -q, --quiet
98                 Enable quiet mode.  In this mode details about syntax errors
99                 are not printed.  This option is only useful when combined
100                 with the -c option.
101
102     -s, --strict
103                 Enable strict checking of the sudoers file.  If an alias is
104                 referenced but not actually defined or if there is a cycle in
105                 an alias, visudo will consider this a syntax error.  It is
106                 not possible to differentiate between an alias and a host
107                 name or user name that consists solely of uppercase letters,
108                 digits, and the underscore (‘_’) character.
109
110     -V, --version
111                 Print the visudo and sudoers grammar versions and exit.
112
113     A sudoers file may be specified instead of the default, /etc/sudoers.
114     The temporary file used is the specified sudoers file with “.tmp” ap‐
115     pended to it.  In check-only mode only, ‘-’ may be used to indicate that
116     sudoers will be read from the standard input.  Because the policy is
117     evaluated in its entirety, it is not sufficient to check an individual
118     sudoers include file for syntax errors.
119
120   Debugging and sudoers plugin arguments
121     visudo versions 1.8.4 and higher support a flexible debugging framework
122     that is configured via Debug lines in the sudo.conf(5) file.
123
124     Starting with sudo 1.8.12, visudo will also parse the arguments to the
125     sudoers plugin to override the default sudoers path name, user-ID, group-
126     ID, and file mode.  These arguments, if present, should be listed after
127     the path to the plugin (i.e., after sudoers.so).  Multiple arguments may
128     be specified, separated by white space.  For example:
129
130         Plugin sudoers_policy sudoers.so sudoers_mode=0400
131
132     The following arguments are supported:
133
134     sudoers_file=pathname
135               The sudoers_file argument can be used to override the default
136               path to the sudoers file.
137
138     sudoers_uid=user-ID
139               The sudoers_uid argument can be used to override the default
140               owner of the sudoers file.  It should be specified as a numeric
141               user-ID.
142
143     sudoers_gid=group-ID
144               The sudoers_gid argument can be used to override the default
145               group of the sudoers file.  It must be specified as a numeric
146               group-ID (not a group name).
147
148     sudoers_mode=mode
149               The sudoers_mode argument can be used to override the default
150               file mode for the sudoers file.  It should be specified as an
151               octal value.
152
153     For more information on configuring sudo.conf(5), refer to its manual.
154

ENVIRONMENT

156     The following environment variables may be consulted depending on the
157     value of the editor and env_editor sudoers settings:
158
159     SUDO_EDITOR      Invoked by visudo as the editor to use
160
161     VISUAL           Used by visudo if SUDO_EDITOR is not set
162
163     EDITOR           Used by visudo if neither SUDO_EDITOR nor VISUAL is set
164

FILES

166     /etc/sudo.conf            Sudo front-end configuration
167
168     /etc/sudoers              List of who can run what
169
170     /etc/sudoers.tmp          Default temporary file used by visudo
171

DIAGNOSTICS

173     In addition to reporting sudoers syntax errors, visudo may produce the
174     following messages:
175
176     sudoers file busy, try again later.
177           Someone else is currently editing the sudoers file.
178
179     /etc/sudoers: Permission denied
180           You didn't run visudo as root.
181
182     you do not exist in the passwd database
183           Your user-ID does not appear in the system passwd database.
184
185     Warning: {User,Runas,Host,Cmnd}_Alias referenced but not defined
186           Either you are trying to use an undeclared
187           {User,Runas,Host,Cmnd}_Alias or you have a user or host name listed
188           that consists solely of uppercase letters, digits, and the under‐
189           score (‘_’) character.  In the latter case, you can ignore the
190           warnings (sudo will not complain).  The message is prefixed with
191           the path name of the sudoers file and the line number where the un‐
192           defined alias was used.  In -s (strict) mode these are errors, not
193           warnings.
194
195     Warning: unused {User,Runas,Host,Cmnd}_Alias
196           The specified {User,Runas,Host,Cmnd}_Alias was defined but never
197           used.  The message is prefixed with the path name of the sudoers
198           file and the line number where the unused alias was defined.  You
199           may wish to comment out or remove the unused alias.
200
201     Warning: cycle in {User,Runas,Host,Cmnd}_Alias
202           The specified {User,Runas,Host,Cmnd}_Alias includes a reference to
203           itself, either directly or through an alias it includes.  The mes‐
204           sage is prefixed with the path name of the sudoers file and the
205           line number where the cycle was detected.  This is only a warning
206           unless visudo is run in -s (strict) mode as sudo will ignore cycles
207           when parsing the sudoers file.
208
209     unknown defaults entry "name"
210           The sudoers file contains a Defaults setting not recognized by
211           visudo.
212

SEE ALSO

214     vi(1), sudo.conf(5), sudoers(5), sudo(8), vipw(8)
215

AUTHORS

217     Many people have worked on sudo over the years; this version consists of
218     code written primarily by:
219
220           Todd C. Miller
221
222     See the CONTRIBUTORS.md file in the sudo distribution
223     (https://www.sudo.ws/about/contributors/) for an exhaustive list of peo‐
224     ple who have contributed to sudo.
225

CAVEATS

227     There is no easy way to prevent a user from gaining a root shell if the
228     editor used by visudo allows shell escapes.
229

BUGS

231     If you believe you have found a bug in visudo, you can submit a bug re‐
232     port at https://bugzilla.sudo.ws/
233

SUPPORT

235     Limited free support is available via the sudo-users mailing list, see
236     https://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search
237     the archives.
238

DISCLAIMER

240     visudo is provided “AS IS” and any express or implied warranties, includ‐
241     ing, but not limited to, the implied warranties of merchantability and
242     fitness for a particular purpose are disclaimed.  See the LICENSE.md file
243     distributed with sudo or https://www.sudo.ws/about/license/ for complete
244     details.
245
246Sudo 1.9.12p2                   October 4, 2022                  Sudo 1.9.12p2
Impressum