1SUDOERS(5) MAINTENANCE COMMANDS SUDOERS(5)
2
3
4
6 sudoers - list of which users may execute what
7
9 The sudoers file is composed of two types of entries: aliases
10 (basically variables) and user specifications (which specify who may
11 run what).
12
13 When multiple entries match for a user, they are applied in order.
14 Where there are multiple matches, the last match is used (which is not
15 necessarily the most specific match).
16
17 The sudoers grammar will be described below in Extended Backus-Naur
18 Form (EBNF). Don't despair if you don't know what EBNF is; it is
19 fairly simple, and the definitions below are annotated.
20
21 Quick guide to EBNF
22 EBNF is a concise and exact way of describing the grammar of a
23 language. Each EBNF definition is made up of production rules. E.g.,
24
25 symbol ::= definition | alternate1 | alternate2 ...
26
27 Each production rule references others and thus makes up a grammar for
28 the language. EBNF also contains the following operators, which many
29 readers will recognize from regular expressions. Do not, however,
30 confuse them with "wildcard" characters, which have different meanings.
31
32 ? Means that the preceding symbol (or group of symbols) is optional.
33 That is, it may appear once or not at all.
34
35 * Means that the preceding symbol (or group of symbols) may appear
36 zero or more times.
37
38 + Means that the preceding symbol (or group of symbols) may appear
39 one or more times.
40
41 Parentheses may be used to group symbols together. For clarity, we
42 will use single quotes ('') to designate what is a verbatim character
43 string (as opposed to a symbol name).
44
45 Aliases
46 There are four kinds of aliases: User_Alias, Runas_Alias, Host_Alias
47 and Cmnd_Alias.
48
49 Alias ::= 'User_Alias' User_Alias (':' User_Alias)* |
50 'Runas_Alias' Runas_Alias (':' Runas_Alias)* |
51 'Host_Alias' Host_Alias (':' Host_Alias)* |
52 'Cmnd_Alias' Cmnd_Alias (':' Cmnd_Alias)*
53
54 User_Alias ::= NAME '=' User_List
55
56 Runas_Alias ::= NAME '=' Runas_List
57
58 Host_Alias ::= NAME '=' Host_List
59
60 Cmnd_Alias ::= NAME '=' Cmnd_List
61
62 NAME ::= [A-Z]([A-Z][0-9]_)*
63
64 Each alias definition is of the form
65
66 Alias_Type NAME = item1, item2, ...
67
68 where Alias_Type is one of User_Alias, Runas_Alias, Host_Alias, or
69 Cmnd_Alias. A NAME is a string of uppercase letters, numbers, and
70 underscore characters ('_'). A NAME must start with an uppercase
71 letter. It is possible to put several alias definitions of the same
72 type on a single line, joined by a colon (':'). E.g.,
73
74 Alias_Type NAME = item1, item2, item3 : NAME = item4, item5
75
76 The definitions of what constitutes a valid alias member follow.
77
78 User_List ::= User |
79 User ',' User_List
80
81 User ::= '!'* user name |
82 '!'* '#'uid |
83 '!'* '%'group |
84 '!'* '+'netgroup |
85 '!'* '%:'nonunix_group |
86 '!'* User_Alias
87
88 A User_List is made up of one or more user names, uids (prefixed with
89 '#'), system groups (prefixed with '%'), netgroups (prefixed with '+')
90 and User_Aliases. Each list item may be prefixed with zero or more '!'
91 operators. An odd number of '!' operators negate the value of the
92 item; an even number just cancel each other out.
93
94 A user name, group, netgroup or nonunix_group may be enclosed in double
95 quotes to avoid the need for escaping special characters. Alternately,
96 special characters may be specified in escaped hex mode, e.g. \x20 for
97 space.
98
99 The nonunix_group syntax depends on the underlying implementation. For
100 instance, the QAS AD backend supports the following formats:
101
102 · Group in the same domain: "Group Name"
103
104 · Group in any domain: "Group Name@FULLY.QUALIFIED.DOMAIN"
105
106 · Group SID: "S-1-2-34-5678901234-5678901234-5678901234-567"
107
108 Note that quotes around group names are optional. Unquoted strings
109 must use a backslash (\) to escape spaces and the '@' symbol.
110
111 Runas_List ::= Runas_Member |
112 Runas_Member ',' Runas_List
113
114 Runas_Member ::= '!'* user name |
115 '!'* '#'uid |
116 '!'* '%'group |
117 '!'* +netgroup |
118 '!'* Runas_Alias
119
120 A Runas_List is similar to a User_List except that instead of
121 User_Aliases it can contain Runas_Aliases. Note that user names and
122 groups are matched as strings. In other words, two users (groups) with
123 the same uid (gid) are considered to be distinct. If you wish to match
124 all user names with the same uid (e.g. root and toor), you can use a
125 uid instead (#0 in the example given).
126
127 Host_List ::= Host |
128 Host ',' Host_List
129
130 Host ::= '!'* host name |
131 '!'* ip_addr |
132 '!'* network(/netmask)? |
133 '!'* '+'netgroup |
134 '!'* Host_Alias
135
136 A Host_List is made up of one or more host names, IP addresses, network
137 numbers, netgroups (prefixed with '+') and other aliases. Again, the
138 value of an item may be negated with the '!' operator. If you do not
139 specify a netmask along with the network number, sudo will query each
140 of the local host's network interfaces and, if the network number
141 corresponds to one of the hosts's network interfaces, the corresponding
142 netmask will be used. The netmask may be specified either in standard
143 IP address notation (e.g. 255.255.255.0 or ffff:ffff:ffff:ffff::), or
144 CIDR notation (number of bits, e.g. 24 or 64). A host name may include
145 shell-style wildcards (see the Wildcards section below), but unless the
146 host name command on your machine returns the fully qualified host
147 name, you'll need to use the fqdn option for wildcards to be useful.
148 Note sudo only inspects actual network interfaces; this means that IP
149 address 127.0.0.1 (localhost) will never match. Also, the host name
150 "localhost" will only match if that is the actual host name, which is
151 usually only the case for non-networked systems.
152
153 Cmnd_List ::= Cmnd |
154 Cmnd ',' Cmnd_List
155
156 commandname ::= file name |
157 file name args |
158 file name '""'
159
160 Cmnd ::= '!'* commandname |
161 '!'* directory |
162 '!'* "sudoedit" |
163 '!'* Cmnd_Alias
164
165 A Cmnd_List is a list of one or more commandnames, directories, and
166 other aliases. A commandname is a fully qualified file name which may
167 include shell-style wildcards (see the Wildcards section below). A
168 simple file name allows the user to run the command with any arguments
169 he/she wishes. However, you may also specify command line arguments
170 (including wildcards). Alternately, you can specify "" to indicate
171 that the command may only be run without command line arguments. A
172 directory is a fully qualified path name ending in a '/'. When you
173 specify a directory in a Cmnd_List, the user will be able to run any
174 file within that directory (but not in any subdirectories therein).
175
176 If a Cmnd has associated command line arguments, then the arguments in
177 the Cmnd must match exactly those given by the user on the command line
178 (or match the wildcards if there are any). Note that the following
179 characters must be escaped with a '\' if they are used in command
180 arguments: ',', ':', '=', '\'. The special command "sudoedit" is used
181 to permit a user to run sudo with the -e option (or as sudoedit). It
182 may take command line arguments just as a normal command does.
183
184 Defaults
185 Certain configuration options may be changed from their default values
186 at runtime via one or more Default_Entry lines. These may affect all
187 users on any host, all users on a specific host, a specific user, a
188 specific command, or commands being run as a specific user. Note that
189 per-command entries may not include command line arguments. If you
190 need to specify arguments, define a Cmnd_Alias and reference that
191 instead.
192
193 Default_Type ::= 'Defaults' |
194 'Defaults' '@' Host_List |
195 'Defaults' ':' User_List |
196 'Defaults' '!' Cmnd_List |
197 'Defaults' '>' Runas_List
198
199 Default_Entry ::= Default_Type Parameter_List
200
201 Parameter_List ::= Parameter |
202 Parameter ',' Parameter_List
203
204 Parameter ::= Parameter '=' Value |
205 Parameter '+=' Value |
206 Parameter '-=' Value |
207 '!'* Parameter
208
209 Parameters may be flags, integer values, strings, or lists. Flags are
210 implicitly boolean and can be turned off via the '!' operator. Some
211 integer, string and list parameters may also be used in a boolean
212 context to disable them. Values may be enclosed in double quotes (")
213 when they contain multiple words. Special characters may be escaped
214 with a backslash (\).
215
216 Lists have two additional assignment operators, += and -=. These
217 operators are used to add to and delete from a list respectively. It
218 is not an error to use the -= operator to remove an element that does
219 not exist in a list.
220
221 Defaults entries are parsed in the following order: generic, host and
222 user Defaults first, then runas Defaults and finally command defaults.
223
224 See "SUDOERS OPTIONS" for a list of supported Defaults parameters.
225
226 User Specification
227 User_Spec ::= User_List Host_List '=' Cmnd_Spec_List \
228 (':' Host_List '=' Cmnd_Spec_List)*
229
230 Cmnd_Spec_List ::= Cmnd_Spec |
231 Cmnd_Spec ',' Cmnd_Spec_List
232
233 Cmnd_Spec ::= Runas_Spec? SELinux_Spec? Tag_Spec* Cmnd
234
235 Runas_Spec ::= '(' Runas_List? (':' Runas_List)? ')'
236
237 SELinux_Spec ::= ('ROLE=role' | 'TYPE=type')
238
239 Tag_Spec ::= ('NOPASSWD:' | 'PASSWD:' | 'NOEXEC:' | 'EXEC:' |
240 'SETENV:' | 'NOSETENV:' | 'LOG_INPUT:' | 'NOLOG_INPUT:' |
241 'LOG_OUTPUT:' | 'NOLOG_OUTPUT:')
242
243 A user specification determines which commands a user may run (and as
244 what user) on specified hosts. By default, commands are run as root,
245 but this can be changed on a per-command basis.
246
247 The basic structure of a user specification is `who = where (as_whom)
248 what'. Let's break that down into its constituent parts:
249
250 Runas_Spec
251 A Runas_Spec determines the user and/or the group that a command may be
252 run as. A fully-specified Runas_Spec consists of two Runas_Lists (as
253 defined above) separated by a colon (':') and enclosed in a set of
254 parentheses. The first Runas_List indicates which users the command
255 may be run as via sudo's -u option. The second defines a list of
256 groups that can be specified via sudo's -g option. If both Runas_Lists
257 are specified, the command may be run with any combination of users and
258 groups listed in their respective Runas_Lists. If only the first is
259 specified, the command may be run as any user in the list but no -g
260 option may be specified. If the first Runas_List is empty but the
261 second is specified, the command may be run as the invoking user with
262 the group set to any listed in the Runas_List. If no Runas_Spec is
263 specified the command may be run as root and no group may be specified.
264
265 A Runas_Spec sets the default for the commands that follow it. What
266 this means is that for the entry:
267
268 dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/lprm
269
270 The user dgb may run /bin/ls, /bin/kill, and /usr/bin/lprm -- but only
271 as operator. E.g.,
272
273 $ sudo -u operator /bin/ls.
274
275 It is also possible to override a Runas_Spec later on in an entry. If
276 we modify the entry like so:
277
278 dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
279
280 Then user dgb is now allowed to run /bin/ls as operator, but /bin/kill
281 and /usr/bin/lprm as root.
282
283 We can extend this to allow dgb to run /bin/ls with either the user or
284 group set to operator:
285
286 dgb boulder = (operator : operator) /bin/ls, (root) /bin/kill, \
287 /usr/bin/lprm
288
289 In the following example, user tcm may run commands that access a modem
290 device file with the dialer group. Note that in this example only the
291 group will be set, the command still runs as user tcm.
292
293 tcm boulder = (:dialer) /usr/bin/tip, /usr/bin/cu, \
294 /usr/local/bin/minicom
295
296 SELinux_Spec
297 On systems with SELinux support, sudoers entries may optionally have an
298 SELinux role and/or type associated with a command. If a role or type
299 is specified with the command it will override any default values
300 specified in sudoers. A role or type specified on the command line,
301 however, will supercede the values in sudoers.
302
303 Tag_Spec
304 A command may have zero or more tags associated with it. There are
305 eight possible tag values, NOPASSWD, PASSWD, NOEXEC, EXEC, SETENV,
306 NOSETENV, LOG_INPUT, NOLOG_INPUT, LOG_OUTPUT and NOLOG_OUTPUT. Once a
307 tag is set on a Cmnd, subsequent Cmnds in the Cmnd_Spec_List, inherit
308 the tag unless it is overridden by the opposite tag (i.e.: PASSWD
309 overrides NOPASSWD and NOEXEC overrides EXEC).
310
311 NOPASSWD and PASSWD
312
313 By default, sudo requires that a user authenticate him or herself
314 before running a command. This behavior can be modified via the
315 NOPASSWD tag. Like a Runas_Spec, the NOPASSWD tag sets a default for
316 the commands that follow it in the Cmnd_Spec_List. Conversely, the
317 PASSWD tag can be used to reverse things. For example:
318
319 ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
320
321 would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm
322 as root on the machine rushmore without authenticating himself. If we
323 only want ray to be able to run /bin/kill without a password the entry
324 would be:
325
326 ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
327
328 Note, however, that the PASSWD tag has no effect on users who are in
329 the group specified by the exempt_group option.
330
331 By default, if the NOPASSWD tag is applied to any of the entries for a
332 user on the current host, he or she will be able to run sudo -l without
333 a password. Additionally, a user may only run sudo -v without a
334 password if the NOPASSWD tag is present for all a user's entries that
335 pertain to the current host. This behavior may be overridden via the
336 verifypw and listpw options.
337
338 NOEXEC and EXEC
339
340 If sudo has been compiled with noexec support and the underlying
341 operating system supports it, the NOEXEC tag can be used to prevent a
342 dynamically-linked executable from running further commands itself.
343
344 In the following example, user aaron may run /usr/bin/more and
345 /usr/bin/vi but shell escapes will be disabled.
346
347 aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
348
349 See the "PREVENTING SHELL ESCAPES" section below for more details on
350 how NOEXEC works and whether or not it will work on your system.
351
352 SETENV and NOSETENV
353
354 These tags override the value of the setenv option on a per-command
355 basis. Note that if SETENV has been set for a command, any environment
356 variables set on the command line way are not subject to the
357 restrictions imposed by env_check, env_delete, or env_keep. As such,
358 only trusted users should be allowed to set variables in this manner.
359 If the command matched is ALL, the SETENV tag is implied for that
360 command; this default may be overridden by use of the NOSETENV tag.
361
362 LOG_INPUT and NOLOG_INPUT
363
364 These tags override the value of the log_input option on a per-command
365 basis. For more information, see the description of log_input in the
366 "SUDOERS OPTIONS" section below.
367
368 LOG_OUTPUT and NOLOG_OUTPUT
369
370 These tags override the value of the log_output option on a per-command
371 basis. For more information, see the description of log_output in the
372 "SUDOERS OPTIONS" section below.
373
374 Wildcards
375 sudo allows shell-style wildcards (aka meta or glob characters) to be
376 used in host names, path names and command line arguments in the
377 sudoers file. Wildcard matching is done via the POSIX [22mglob(3) and
378 fnmatch(3) routines. Note that these are not regular expressions.
379
380 * Matches any set of zero or more characters.
381
382 ? Matches any single character.
383
384 [...] Matches any character in the specified range.
385
386 [!...] Matches any character not in the specified range.
387
388 \x For any character "x", evaluates to "x". This is used to
389 escape special characters such as: "*", "?", "[", and "}".
390
391 POSIX character classes may also be used if your system's glob(3) and
392 fnmatch(3) functions support them. However, because the ':' character
393 has special meaning in sudoers, it must be escaped. For example:
394
395 /bin/ls [[\:alpha\:]]*
396
397 Would match any file name beginning with a letter.
398
399 Note that a forward slash ('/') will not be matched by wildcards used
400 in the path name. When matching the command line arguments, however, a
401 slash does get matched by wildcards. This is to make a path like:
402
403 /usr/bin/*
404
405 match /usr/bin/who but not /usr/bin/X11/xterm.
406
407 Exceptions to wildcard rules
408 The following exceptions apply to the above rules:
409
410 "" If the empty string "" is the only command line argument in the
411 sudoers entry it means that command is not allowed to be run
412 with any arguments.
413
414 Including other files from within sudoers
415 It is possible to include other sudoers files from within the sudoers
416 file currently being parsed using the #include and #includedir
417 directives.
418
419 This can be used, for example, to keep a site-wide sudoers file in
420 addition to a local, per-machine file. For the sake of this example
421 the site-wide sudoers will be /etc/sudoers and the per-machine one will
422 be /etc/sudoers.local. To include /etc/sudoers.local from within
423 /etc/sudoers we would use the following line in /etc/sudoers:
424
425 #include /etc/sudoers.local
426
427 When sudo reaches this line it will suspend processing of the current
428 file (/etc/sudoers) and switch to /etc/sudoers.local. Upon reaching
429 the end of /etc/sudoers.local, the rest of /etc/sudoers will be
430 processed. Files that are included may themselves include other files.
431 A hard limit of 128 nested include files is enforced to prevent include
432 file loops.
433
434 The file name may include the %h escape, signifying the short form of
435 the host name. I.e., if the machine's host name is "xerxes", then
436
437 #include /etc/sudoers.%h
438
439 will cause sudo to include the file /etc/sudoers.xerxes.
440
441 The #includedir directive can be used to create a sudo.d directory that
442 the system package manager can drop sudoers rules into as part of
443 package installation. For example, given:
444
445 #includedir /etc/sudoers.d
446
447 sudo will read each file in /etc/sudoers.d, skipping file names that
448 end in ~ or contain a . character to avoid causing problems with
449 package manager or editor temporary/backup files. Files are parsed in
450 sorted lexical order. That is, /etc/sudoers.d/01_first will be parsed
451 before /etc/sudoers.d/10_second. Be aware that because the sorting is
452 lexical, not numeric, /etc/sudoers.d/1_whoops would be loaded after
453 /etc/sudoers.d/10_second. Using a consistent number of leading zeroes
454 in the file names can be used to avoid such problems.
455
456 Note that unlike files included via #include, visudo will not edit the
457 files in a #includedir directory unless one of them contains a syntax
458 error. It is still possible to run visudo with the -f flag to edit the
459 files directly.
460
461 Other special characters and reserved words
462 The pound sign ('#') is used to indicate a comment (unless it is part
463 of a #include directive or unless it occurs in the context of a user
464 name and is followed by one or more digits, in which case it is treated
465 as a uid). Both the comment character and any text after it, up to the
466 end of the line, are ignored.
467
468 The reserved word ALL is a built-in alias that always causes a match to
469 succeed. It can be used wherever one might otherwise use a Cmnd_Alias,
470 User_Alias, Runas_Alias, or Host_Alias. You should not try to define
471 your own alias called ALL as the built-in alias will be used in
472 preference to your own. Please note that using ALL can be dangerous
473 since in a command context, it allows the user to run any command on
474 the system.
475
476 An exclamation point ('!') can be used as a logical not operator both
477 in an alias and in front of a Cmnd. This allows one to exclude certain
478 values. Note, however, that using a ! in conjunction with the built-in
479 ALL alias to allow a user to run "all but a few" commands rarely works
480 as intended (see SECURITY NOTES below).
481
482 Long lines can be continued with a backslash ('\') as the last
483 character on the line.
484
485 Whitespace between elements in a list as well as special syntactic
486 characters in a User Specification ('=', ':', '(', ')') is optional.
487
488 The following characters must be escaped with a backslash ('\') when
489 used as part of a word (e.g. a user name or host name): '@', '!', '=',
490 ':', ',', '(', ')', '\'.
491
493 sudo's behavior can be modified by Default_Entry lines, as explained
494 earlier. A list of all supported Defaults parameters, grouped by type,
495 are listed below.
496
497 Boolean Flags:
498
499 always_set_home If enabled, sudo will set the HOME environment variable
500 to the home directory of the target user (which is root
501 unless the -u option is used). This effectively means
502 that the -H option is always implied. Note that HOME
503 is already set when the the env_reset option is
504 enabled, so always_set_home is only effective for
505 configurations where env_reset is disabled. This flag
506 is off by default.
507
508 authenticate If set, users must authenticate themselves via a
509 password (or other means of authentication) before they
510 may run commands. This default may be overridden via
511 the PASSWD and NOPASSWD tags. This flag is on by
512 default.
513
514 closefrom_override
515 If set, the user may use sudo's -C option which
516 overrides the default starting point at which sudo
517 begins closing open file descriptors. This flag is off
518 by default.
519
520 compress_io If set, and sudo is configured to log a command's input
521 or output, the I/O logs will be compressed using zlib.
522 This flag is on by default when sudo is compiled with
523 zlib support.
524
525 env_editor If set, visudo will use the value of the EDITOR or
526 VISUAL environment variables before falling back on the
527 default editor list. Note that this may create a
528 security hole as it allows the user to run any
529 arbitrary command as root without logging. A safer
530 alternative is to place a colon-separated list of
531 editors in the editor variable. visudo will then only
532 use the EDITOR or VISUAL if they match a value
533 specified in editor. This flag is on by default.
534
535 env_reset If set, sudo will reset the environment to only contain
536 the LOGNAME, MAIL, SHELL, USER, USERNAME and the SUDO_*
537 variables. Any variables in the caller's environment
538 that match the env_keep and env_check lists are then
539 added. The default contents of the env_keep and
540 env_check lists are displayed when sudo is run by root
541 with the -V option. If the secure_path option is set,
542 its value will be used for the PATH environment
543 variable. This flag is on by default.
544
545 fast_glob Normally, sudo uses the glob(3) function to do shell-
546 style globbing when matching path names. However,
547 since it accesses the file system, glob(3) can take a
548 long time to complete for some patterns, especially
549 when the pattern references a network file system that
550 is mounted on demand (automounted). The fast_glob
551 option causes sudo to use the fnmatch(3) function,
552 which does not access the file system to do its
553 matching. The disadvantage of fast_glob is that it is
554 unable to match relative path names such as ./ls or
555 ../bin/ls. This has security implications when path
556 names that include globbing characters are used with
557 the negation operator, '!', as such rules can be
558 trivially bypassed. As such, this option should not be
559 used when sudoers contains rules that contain negated
560 path names which include globbing characters. This
561 flag is off by default.
562
563 fqdn Set this flag if you want to put fully qualified host
564 names in the sudoers file. I.e., instead of myhost you
565 would use myhost.mydomain.edu. You may still use the
566 short form if you wish (and even mix the two). Beware
567 that turning on fqdn requires sudo to make DNS lookups
568 which may make sudo unusable if DNS stops working (for
569 example if the machine is not plugged into the
570 network). Also note that you must use the host's
571 official name as DNS knows it. That is, you may not
572 use a host alias (CNAME entry) due to performance
573 issues and the fact that there is no way to get all
574 aliases from DNS. If your machine's host name (as
575 returned by the hostname command) is already fully
576 qualified you shouldn't need to set fqdn. This flag is
577 off by default.
578
579 ignore_dot If set, sudo will ignore '.' or '' (current dir) in the
580 PATH environment variable; the PATH itself is not
581 modified. This flag is on by default.
582
583 ignore_local_sudoers
584 If set via LDAP, parsing of /etc/sudoers will be
585 skipped. This is intended for Enterprises that wish to
586 prevent the usage of local sudoers files so that only
587 LDAP is used. This thwarts the efforts of rogue
588 operators who would attempt to add roles to
589 /etc/sudoers. When this option is present,
590 /etc/sudoers does not even need to exist. Since this
591 option tells sudo how to behave when no specific LDAP
592 entries have been matched, this sudoOption is only
593 meaningful for the cn=defaults section. This flag is
594 off by default.
595
596 insults If set, sudo will insult users when they enter an
597 incorrect password. This flag is off by default.
598
599 log_host If set, the host name will be logged in the (non-
600 syslog) sudo log file. This flag is off by default.
601
602 log_year If set, the four-digit year will be logged in the (non-
603 syslog) sudo log file. This flag is off by default.
604
605 long_otp_prompt When validating with a One Time Password (OPT) scheme
606 such as S/Key or OPIE, a two-line prompt is used to
607 make it easier to cut and paste the challenge to a
608 local window. It's not as pretty as the default but
609 some people find it more convenient. This flag is off
610 by default.
611
612 mail_always Send mail to the mailto user every time a users runs
613 sudo. This flag is off by default.
614
615 mail_badpass Send mail to the mailto user if the user running sudo
616 does not enter the correct password. This flag is off
617 by default.
618
619 mail_no_host If set, mail will be sent to the mailto user if the
620 invoking user exists in the sudoers file, but is not
621 allowed to run commands on the current host. This flag
622 is off by default.
623
624 mail_no_perms If set, mail will be sent to the mailto user if the
625 invoking user is allowed to use sudo but the command
626 they are trying is not listed in their sudoers file
627 entry or is explicitly denied. This flag is off by
628 default.
629
630 mail_no_user If set, mail will be sent to the mailto user if the
631 invoking user is not in the sudoers file. This flag is
632 on by default.
633
634 noexec If set, all commands run via sudo will behave as if the
635 NOEXEC tag has been set, unless overridden by a EXEC
636 tag. See the description of NOEXEC and EXEC below as
637 well as the "PREVENTING SHELL ESCAPES" section at the
638 end of this manual. This flag is off by default.
639
640 path_info Normally, sudo will tell the user when a command could
641 not be found in their PATH environment variable. Some
642 sites may wish to disable this as it could be used to
643 gather information on the location of executables that
644 the normal user does not have access to. The
645 disadvantage is that if the executable is simply not in
646 the user's PATH, sudo will tell the user that they are
647 not allowed to run it, which can be confusing. This
648 flag is on by default.
649
650 passprompt_override
651 The password prompt specified by passprompt will
652 normally only be used if the password prompt provided
653 by systems such as PAM matches the string "Password:".
654 If passprompt_override is set, passprompt will always
655 be used. This flag is off by default.
656
657 preserve_groups By default, sudo will initialize the group vector to
658 the list of groups the target user is in. When
659 preserve_groups is set, the user's existing group
660 vector is left unaltered. The real and effective group
661 IDs, however, are still set to match the target user.
662 This flag is off by default.
663
664 pwfeedback By default, sudo reads the password like most other
665 Unix programs, by turning off echo until the user hits
666 the return (or enter) key. Some users become confused
667 by this as it appears to them that sudo has hung at
668 this point. When pwfeedback is set, sudo will provide
669 visual feedback when the user presses a key. Note that
670 this does have a security impact as an onlooker may be
671 able to determine the length of the password being
672 entered. This flag is off by default.
673
674 requiretty If set, sudo will only run when the user is logged in
675 to a real tty. When this flag is set, sudo can only be
676 run from a login session and not via other means such
677 as cron(8) or cgi-bin scripts. This flag is off by
678 default.
679
680 root_sudo If set, root is allowed to run sudo too. Disabling
681 this prevents users from "chaining" sudo commands to
682 get a root shell by doing something like "sudo sudo
683 /bin/sh". Note, however, that turning off root_sudo
684 will also prevent root from running sudoedit.
685 Disabling root_sudo provides no real additional
686 security; it exists purely for historical reasons.
687 This flag is on by default.
688
689 rootpw If set, sudo will prompt for the root password instead
690 of the password of the invoking user. This flag is off
691 by default.
692
693 runaspw If set, sudo will prompt for the password of the user
694 defined by the runas_default option (defaults to root)
695 instead of the password of the invoking user. This
696 flag is off by default.
697
698 set_home If enabled and sudo is invoked with the -s option the
699 HOME environment variable will be set to the home
700 directory of the target user (which is root unless the
701 -u option is used). This effectively makes the -s
702 option imply -H. Note that HOME is already set when
703 the the env_reset option is enabled, so set_home is
704 only effective for configurations where env_reset is
705 disabled. This flag is off by default.
706
707 set_logname Normally, sudo will set the LOGNAME, USER and USERNAME
708 environment variables to the name of the target user
709 (usually root unless the -u option is given). However,
710 since some programs (including the RCS revision control
711 system) use LOGNAME to determine the real identity of
712 the user, it may be desirable to change this behavior.
713 This can be done by negating the set_logname option.
714 Note that if the env_reset option has not been
715 disabled, entries in the env_keep list will override
716 the value of set_logname. This flag is on by default.
717
718 setenv Allow the user to disable the env_reset option from the
719 command line. Additionally, environment variables set
720 via the command line are not subject to the
721 restrictions imposed by env_check, env_delete, or
722 env_keep. As such, only trusted users should be
723 allowed to set variables in this manner. This flag is
724 off by default.
725
726 shell_noargs If set and sudo is invoked with no arguments it acts as
727 if the -s option had been given. That is, it runs a
728 shell as root (the shell is determined by the SHELL
729 environment variable if it is set, falling back on the
730 shell listed in the invoking user's /etc/passwd entry
731 if not). This flag is off by default.
732
733 stay_setuid Normally, when sudo executes a command the real and
734 effective UIDs are set to the target user (root by
735 default). This option changes that behavior such that
736 the real UID is left as the invoking user's UID. In
737 other words, this makes sudo act as a setuid wrapper.
738 This can be useful on systems that disable some
739 potentially dangerous functionality when a program is
740 run setuid. This option is only effective on systems
741 with either the setreuid() or setresuid() function.
742 This flag is off by default.
743
744 targetpw If set, sudo will prompt for the password of the user
745 specified by the -u option (defaults to root) instead
746 of the password of the invoking user. In addition, the
747 timestamp file name will include the target user's
748 name. Note that this flag precludes the use of a uid
749 not listed in the passwd database as an argument to the
750 -u option. This flag is off by default.
751
752 log_input If set, sudo will run the command in a pseudo tty and
753 log all user input. If the standard input is not
754 connected to the user's tty, due to I/O redirection or
755 because the command is part of a pipeline, that input
756 is also captured and stored in a separate log file.
757
758 Input is logged to the /var/log/sudo-io directory using
759 a unique session ID that is included in the normal sudo
760 log line, prefixed with TSID=.
761
762 log_output If set, sudo will run the command in a pseudo tty and
763 log all output that is sent to the screen, similar to
764 the script(1) command. If the standard output or
765 standard error is not connected to the user's tty, due
766 to I/O redirection or because the command is part of a
767 pipeline, that output is also captured and stored in
768 separate log files.
769
770 Output is logged to the /var/log/sudo-io directory
771 using a unique session ID that is included in the
772 normal sudo log line, prefixed with TSID=.
773
774 Output logs may be viewed with the sudoreplay(8)
775 utility, which can also be used to list or search the
776 available logs.
777
778 tty_tickets If set, users must authenticate on a per-tty basis.
779 With this flag enabled, sudo will use a file named for
780 the tty the user is logged in on in the user's time
781 stamp directory. If disabled, the time stamp of the
782 directory is used instead. This flag is on by default.
783
784 umask_override If set, sudo will set the umask as specified by sudoers
785 without modification. This makes it possible to
786 specify a more permissive umask in sudoers than the
787 user's own umask and matches historical behavior. If
788 umask_override is not set, sudo will set the umask to
789 be the union of the user's umask and what is specified
790 in sudoers. This flag is off by default.
791
792 use_pty If set, sudo will run the command in a pseudo-pty even
793 if no I/O logging is being gone. A malicious program
794 run under sudo could conceivably fork a background
795 process that retains to the user's terminal device
796 after the main program has finished executing. Use of
797 this option will make that impossible.
798
799 visiblepw By default, sudo will refuse to run if the user must
800 enter a password but it is not possible to disable echo
801 on the terminal. If the visiblepw flag is set, sudo
802 will prompt for a password even when it would be
803 visible on the screen. This makes it possible to run
804 things like "rsh somehost sudo ls" since rsh(1) does
805 not allocate a tty. This flag is off by default.
806
807 Integers:
808
809 closefrom Before it executes a command, sudo will close all open
810 file descriptors other than standard input, standard
811 output and standard error (ie: file descriptors 0-2).
812 The closefrom option can be used to specify a different
813 file descriptor at which to start closing. The default
814 is 3.
815
816 passwd_tries The number of tries a user gets to enter his/her
817 password before sudo logs the failure and exits. The
818 default is 3.
819
820 Integers that can be used in a boolean context:
821
822 loglinelen Number of characters per line for the file log. This
823 value is used to decide when to wrap lines for nicer
824 log files. This has no effect on the syslog log file,
825 only the file log. The default is 80 (use 0 or negate
826 the option to disable word wrap).
827
828 passwd_timeout Number of minutes before the sudo password prompt times
829 out, or 0 for no timeout. The timeout may include a
830 fractional component if minute granularity is
831 insufficient, for example 2.5. The default is 5.
832
833 timestamp_timeout
834 Number of minutes that can elapse before sudo will ask
835 for a passwd again. The timeout may include a
836 fractional component if minute granularity is
837 insufficient, for example 2.5. The default is 5. Set
838 this to 0 to always prompt for a password. If set to a
839 value less than 0 the user's timestamp will never
840 expire. This can be used to allow users to create or
841 delete their own timestamps via sudo -v and sudo -k
842 respectively.
843
844 umask Umask to use when running the command. Negate this
845 option or set it to 0777 to preserve the user's umask.
846 The actual umask that is used will be the union of the
847 user's umask and the value of the umask option, which
848 defaults to 0022. This guarantees that sudo never
849 lowers the umask when running a command. Note on
850 systems that use PAM, the default PAM configuration may
851 specify its own umask which will override the value set
852 in sudoers.
853
854 Strings:
855
856 badpass_message Message that is displayed if a user enters an incorrect
857 password. The default is Sorry, try again. unless
858 insults are enabled.
859
860 editor A colon (':') separated list of editors allowed to be
861 used with visudo. visudo will choose the editor that
862 matches the user's EDITOR environment variable if
863 possible, or the first editor in the list that exists
864 and is executable. The default is "/bin/vi".
865
866 mailsub Subject of the mail sent to the mailto user. The escape
867 %h will expand to the host name of the machine.
868 Default is *** SECURITY information for %h ***.
869
870 noexec_file Path to a shared library containing dummy versions of
871 the execv(), execve() and fexecve() library functions
872 that just return an error. This is used to implement
873 the noexec functionality on systems that support
874 LD_PRELOAD or its equivalent. Defaults to
875 /usr/libexec/sudo_noexec.so.
876
877 passprompt The default prompt to use when asking for a password;
878 can be overridden via the -p option or the SUDO_PROMPT
879 environment variable. The following percent (`%')
880 escapes are supported:
881
882 %H expanded to the local host name including the
883 domain name (on if the machine's host name is fully
884 qualified or the fqdn option is set)
885
886 %h expanded to the local host name without the domain
887 name
888
889 %p expanded to the user whose password is being asked
890 for (respects the rootpw, targetpw and runaspw
891 flags in sudoers)
892
893 %U expanded to the login name of the user the command
894 will be run as (defaults to root)
895
896 %u expanded to the invoking user's login name
897
898 %% two consecutive % characters are collapsed into a
899 single % character
900
901 The default value is [sudo] password for %p: .
902
903 role The default SELinux role to use when constructing a new
904 security context to run the command. The default role
905 may be overridden on a per-command basis in sudoers or
906 via command line options. This option is only
907 available whe sudo is built with SELinux support.
908
909 runas_default The default user to run commands as if the -u option is
910 not specified on the command line. This defaults to
911 root. Note that if runas_default is set it must occur
912 before any Runas_Alias specifications.
913
914 syslog_badpri Syslog priority to use when user authenticates
915 unsuccessfully. Defaults to alert.
916
917 syslog_goodpri Syslog priority to use when user authenticates
918 successfully. Defaults to notice.
919
920 sudoers_locale Locale to use when parsing the sudoers file. Note that
921 changing the locale may affect how sudoers is
922 interpreted. Defaults to "C".
923
924 timestampdir The directory in which sudo stores its timestamp files.
925 The default is /var/db/sudo.
926
927 timestampowner The owner of the timestamp directory and the timestamps
928 stored therein. The default is root.
929
930 type The default SELinux type to use when constructing a new
931 security context to run the command. The default type
932 may be overridden on a per-command basis in sudoers or
933 via command line options. This option is only
934 available whe sudo is built with SELinux support.
935
936 Strings that can be used in a boolean context:
937
938 askpass The askpass option specifies the fully qualified path to a
939 helper program used to read the user's password when no
940 terminal is available. This may be the case when sudo is
941 executed from a graphical (as opposed to text-based)
942 application. The program specified by askpass should
943 display the argument passed to it as the prompt and write
944 the user's password to the standard output. The value of
945 askpass may be overridden by the SUDO_ASKPASS environment
946 variable.
947
948 env_file The env_file options specifies the fully qualified path to
949 a file containing variables to be set in the environment of
950 the program being run. Entries in this file should either
951 be of the form VARIABLE=value or export VARIABLE=value.
952 The value may optionally be surrounded by single or double
953 quotes. Variables in this file are subject to other sudo
954 environment settings such as env_keep and env_check.
955
956 exempt_group
957 Users in this group are exempt from password and PATH
958 requirements. This is not set by default.
959
960 lecture This option controls when a short lecture will be printed
961 along with the password prompt. It has the following
962 possible values:
963
964 always Always lecture the user.
965
966 never Never lecture the user.
967
968 once Only lecture the user the first time they run sudo.
969
970 If no value is specified, a value of once is implied.
971 Negating the option results in a value of never being used.
972 The default value is once.
973
974 lecture_file
975 Path to a file containing an alternate sudo lecture that
976 will be used in place of the standard lecture if the named
977 file exists. By default, sudo uses a built-in lecture.
978
979 listpw This option controls when a password will be required when
980 a user runs sudo with the -l option. It has the following
981 possible values:
982
983 all All the user's sudoers entries for the current host
984 must have the NOPASSWD flag set to avoid entering a
985 password.
986
987 always The user must always enter a password to use the -l
988 option.
989
990 any At least one of the user's sudoers entries for the
991 current host must have the NOPASSWD flag set to
992 avoid entering a password.
993
994 never The user need never enter a password to use the -l
995 option.
996
997 If no value is specified, a value of any is implied.
998 Negating the option results in a value of never being used.
999 The default value is any.
1000
1001 logfile Path to the sudo log file (not the syslog log file).
1002 Setting a path turns on logging to a file; negating this
1003 option turns it off. By default, sudo logs via syslog.
1004
1005 mailerflags Flags to use when invoking mailer. Defaults to -t.
1006
1007 mailerpath Path to mail program used to send warning mail. Defaults
1008 to the path to sendmail found at configure time.
1009
1010 mailfrom Address to use for the "from" address when sending warning
1011 and error mail. The address should be enclosed in double
1012 quotes (") to protect against sudo interpreting the @ sign.
1013 Defaults to the name of the user running sudo.
1014
1015 mailto Address to send warning and error mail to. The address
1016 should be enclosed in double quotes (") to protect against
1017 sudo interpreting the @ sign. Defaults to root.
1018
1019 secure_path Path used for every command run from sudo. If you don't
1020 trust the people running sudo to have a sane PATH
1021 environment variable you may want to use this. Another use
1022 is if you want to have the "root path" be separate from the
1023 "user path." Users in the group specified by the
1024 exempt_group option are not affected by secure_path. This
1025 option is not set by default.
1026
1027 syslog Syslog facility if syslog is being used for logging (negate
1028 to disable syslog logging). Defaults to authpriv.
1029
1030 verifypw This option controls when a password will be required when
1031 a user runs sudo with the -v option. It has the following
1032 possible values:
1033
1034 all All the user's sudoers entries for the current host
1035 must have the NOPASSWD flag set to avoid entering a
1036 password.
1037
1038 always The user must always enter a password to use the -v
1039 option.
1040
1041 any At least one of the user's sudoers entries for the
1042 current host must have the NOPASSWD flag set to
1043 avoid entering a password.
1044
1045 never The user need never enter a password to use the -v
1046 option.
1047
1048 If no value is specified, a value of all is implied.
1049 Negating the option results in a value of never being used.
1050 The default value is all.
1051
1052 Lists that can be used in a boolean context:
1053
1054 env_check Environment variables to be removed from the user's
1055 environment if the variable's value contains % or /
1056 characters. This can be used to guard against printf-
1057 style format vulnerabilities in poorly-written
1058 programs. The argument may be a double-quoted, space-
1059 separated list or a single value without double-quotes.
1060 The list can be replaced, added to, deleted from, or
1061 disabled by using the =, +=, -=, and ! operators
1062 respectively. Regardless of whether the env_reset
1063 option is enabled or disabled, variables specified by
1064 env_check will be preserved in the environment if they
1065 pass the aforementioned check. The default list of
1066 environment variables to check is displayed when sudo
1067 is run by root with the -V option.
1068
1069 env_delete Environment variables to be removed from the user's
1070 environment when the env_reset option is not in effect.
1071 The argument may be a double-quoted, space-separated
1072 list or a single value without double-quotes. The list
1073 can be replaced, added to, deleted from, or disabled by
1074 using the =, +=, -=, and ! operators respectively. The
1075 default list of environment variables to remove is
1076 displayed when sudo is run by root with the -V option.
1077 Note that many operating systems will remove
1078 potentially dangerous variables from the environment of
1079 any setuid process (such as sudo).
1080
1081 env_keep Environment variables to be preserved in the user's
1082 environment when the env_reset option is in effect.
1083 This allows fine-grained control over the environment
1084 sudo-spawned processes will receive. The argument may
1085 be a double-quoted, space-separated list or a single
1086 value without double-quotes. The list can be replaced,
1087 added to, deleted from, or disabled by using the =, +=,
1088 -=, and ! operators respectively. The default list of
1089 variables to keep is displayed when sudo is run by root
1090 with the -V option.
1091
1092 When logging via syslog(3), sudo accepts the following values for the
1093 syslog facility (the value of the syslog Parameter): authpriv (if your
1094 OS supports it), auth, daemon, user, local0, local1, local2, local3,
1095 local4, local5, local6, and local7. The following syslog priorities
1096 are supported: alert, crit, debug, emerg, err, info, notice, and
1097 warning.
1098
1100 /etc/sudoers List of who can run what
1101
1102 /etc/group Local groups file
1103
1104 /etc/netgroup List of network groups
1105
1106 /var/log/sudo-io I/O log files
1107
1109 Below are example sudoers entries. Admittedly, some of these are a bit
1110 contrived. First, we allow a few environment variables to pass and
1111 then define our aliases:
1112
1113 # Run X applications through sudo; HOME is used to find the
1114 # .Xauthority file. Note that other programs use HOME to find
1115 # configuration files and this may lead to privilege escalation!
1116 Defaults env_keep += "DISPLAY HOME"
1117
1118 # User alias specification
1119 User_Alias FULLTIMERS = millert, mikef, dowdy
1120 User_Alias PARTTIMERS = bostley, jwfox, crawl
1121 User_Alias WEBMASTERS = will, wendy, wim
1122
1123 # Runas alias specification
1124 Runas_Alias OP = root, operator
1125 Runas_Alias DB = oracle, sybase
1126 Runas_Alias ADMINGRP = adm, oper
1127
1128 # Host alias specification
1129 Host_Alias SPARC = bigtime, eclipse, moet, anchor :\
1130 SGI = grolsch, dandelion, black :\
1131 ALPHA = widget, thalamus, foobar :\
1132 HPPA = boa, nag, python
1133 Host_Alias CUNETS = 128.138.0.0/255.255.0.0
1134 Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
1135 Host_Alias SERVERS = master, mail, www, ns
1136 Host_Alias CDROM = orion, perseus, hercules
1137
1138 # Cmnd alias specification
1139 Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
1140 /usr/sbin/restore, /usr/sbin/rrestore
1141 Cmnd_Alias KILL = /usr/bin/kill
1142 Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm
1143 Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown
1144 Cmnd_Alias HALT = /usr/sbin/halt
1145 Cmnd_Alias REBOOT = /usr/sbin/reboot
1146 Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
1147 /usr/local/bin/tcsh, /usr/bin/rsh, \
1148 /usr/local/bin/zsh
1149 Cmnd_Alias SU = /usr/bin/su
1150 Cmnd_Alias PAGERS = /usr/bin/more, /usr/bin/pg, /usr/bin/less
1151
1152 Here we override some of the compiled in default values. We want sudo
1153 to log via syslog(3) using the auth facility in all cases. We don't
1154 want to subject the full time staff to the sudo lecture, user millert
1155 need not give a password, and we don't want to reset the LOGNAME, USER
1156 or USERNAME environment variables when running commands as root.
1157 Additionally, on the machines in the SERVERS Host_Alias, we keep an
1158 additional local log file and make sure we log the year in each log
1159 line since the log entries will be kept around for several years.
1160 Lastly, we disable shell escapes for the commands in the PAGERS
1161 Cmnd_Alias (/usr/bin/more, /usr/bin/pg and /usr/bin/less).
1162
1163 # Override built-in defaults
1164 Defaults syslog=auth
1165 Defaults>root !set_logname
1166 Defaults:FULLTIMERS !lecture
1167 Defaults:millert !authenticate
1168 Defaults@SERVERS log_year, logfile=/var/log/sudo.log
1169 Defaults!PAGERS noexec
1170
1171 The User specification is the part that actually determines who may run
1172 what.
1173
1174 root ALL = (ALL) ALL
1175 %wheel ALL = (ALL) ALL
1176
1177 We let root and any user in group wheel run any command on any host as
1178 any user.
1179
1180 FULLTIMERS ALL = NOPASSWD: ALL
1181
1182 Full time sysadmins (millert, mikef, and dowdy) may run any command on
1183 any host without authenticating themselves.
1184
1185 PARTTIMERS ALL = ALL
1186
1187 Part time sysadmins (bostley, jwfox, and crawl) may run any command on
1188 any host but they must authenticate themselves first (since the entry
1189 lacks the NOPASSWD tag).
1190
1191 jack CSNETS = ALL
1192
1193 The user jack may run any command on the machines in the CSNETS alias
1194 (the networks 128.138.243.0, 128.138.204.0, and 128.138.242.0). Of
1195 those networks, only 128.138.204.0 has an explicit netmask (in CIDR
1196 notation) indicating it is a class C network. For the other networks
1197 in CSNETS, the local machine's netmask will be used during matching.
1198
1199 lisa CUNETS = ALL
1200
1201 The user lisa may run any command on any host in the CUNETS alias (the
1202 class B network 128.138.0.0).
1203
1204 operator ALL = DUMPS, KILL, SHUTDOWN, HALT, REBOOT, PRINTING,\
1205 sudoedit /etc/printcap, /usr/oper/bin/
1206
1207 The operator user may run commands limited to simple maintenance.
1208 Here, those are commands related to backups, killing processes, the
1209 printing system, shutting down the system, and any commands in the
1210 directory /usr/oper/bin/.
1211
1212 joe ALL = /usr/bin/su operator
1213
1214 The user joe may only su(1) to operator.
1215
1216 pete HPPA = /usr/bin/passwd [A-Za-z]*, !/usr/bin/passwd root
1217
1218 %opers ALL = (: ADMINGRP) /usr/sbin/
1219
1220 Users in the opers group may run commands in /usr/sbin/ as themselves
1221 with any group in the ADMINGRP Runas_Alias (the adm and oper groups).
1222
1223 The user pete is allowed to change anyone's password except for root on
1224 the HPPA machines. Note that this assumes passwd(1) does not take
1225 multiple user names on the command line.
1226
1227 bob SPARC = (OP) ALL : SGI = (OP) ALL
1228
1229 The user bob may run anything on the SPARC and SGI machines as any user
1230 listed in the OP Runas_Alias (root and operator).
1231
1232 jim +biglab = ALL
1233
1234 The user jim may run any command on machines in the biglab netgroup.
1235 sudo knows that "biglab" is a netgroup due to the '+' prefix.
1236
1237 +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
1238
1239 Users in the secretaries netgroup need to help manage the printers as
1240 well as add and remove users, so they are allowed to run those commands
1241 on all machines.
1242
1243 fred ALL = (DB) NOPASSWD: ALL
1244
1245 The user fred can run commands as any user in the DB Runas_Alias
1246 (oracle or sybase) without giving a password.
1247
1248 john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
1249
1250 On the ALPHA machines, user john may su to anyone except root but he is
1251 not allowed to specify any options to the su(1) command.
1252
1253 jen ALL, !SERVERS = ALL
1254
1255 The user jen may run any command on any machine except for those in the
1256 SERVERS Host_Alias (master, mail, www and ns).
1257
1258 jill SERVERS = /usr/bin/, !SU, !SHELLS
1259
1260 For any machine in the SERVERS Host_Alias, jill may run any commands in
1261 the directory /usr/bin/ except for those commands belonging to the SU
1262 and SHELLS Cmnd_Aliases.
1263
1264 steve CSNETS = (operator) /usr/local/op_commands/
1265
1266 The user steve may run any command in the directory
1267 /usr/local/op_commands/ but only as user operator.
1268
1269 matt valkyrie = KILL
1270
1271 On his personal workstation, valkyrie, matt needs to be able to kill
1272 hung processes.
1273
1274 WEBMASTERS www = (www) ALL, (root) /usr/bin/su www
1275
1276 On the host www, any user in the WEBMASTERS User_Alias (will, wendy,
1277 and wim), may run any command as user www (which owns the web pages) or
1278 simply su(1) to www.
1279
1280 ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\
1281 /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
1282
1283 Any user may mount or unmount a CD-ROM on the machines in the CDROM
1284 Host_Alias (orion, perseus, hercules) without entering a password.
1285 This is a bit tedious for users to type, so it is a prime candidate for
1286 encapsulating in a shell script.
1287
1289 It is generally not effective to "subtract" commands from ALL using the
1290 '!' operator. A user can trivially circumvent this by copying the
1291 desired command to a different name and then executing that. For
1292 example:
1293
1294 bill ALL = ALL, !SU, !SHELLS
1295
1296 Doesn't really prevent bill from running the commands listed in SU or
1297 SHELLS since he can simply copy those commands to a different name, or
1298 use a shell escape from an editor or other program. Therefore, these
1299 kind of restrictions should be considered advisory at best (and
1300 reinforced by policy).
1301
1302 Furthermore, if the fast_glob option is in use, it is not possible to
1303 reliably negate commands where the path name includes globbing (aka
1304 wildcard) characters. This is because the C library's fnmatch(3)
1305 function cannot resolve relative paths. While this is typically only
1306 an inconvenience for rules that grant privileges, it can result in a
1307 security issue for rules that subtract or revoke privileges.
1308
1309 For example, given the following sudoers entry:
1310
1311 john ALL = /usr/bin/passwd [a-zA-Z0-9]*, /usr/bin/chsh [a-zA-Z0-9]*,
1312 /usr/bin/chfn [a-zA-Z0-9]*, !/usr/bin/* root
1313
1314 User john can still run /usr/bin/passwd root if fast_glob is enabled by
1315 changing to /usr/bin and running ./passwd root instead.
1316
1318 Once sudo executes a program, that program is free to do whatever it
1319 pleases, including run other programs. This can be a security issue
1320 since it is not uncommon for a program to allow shell escapes, which
1321 lets a user bypass sudo's access control and logging. Common programs
1322 that permit shell escapes include shells (obviously), editors,
1323 paginators, mail and terminal programs.
1324
1325 There are two basic approaches to this problem:
1326
1327 restrict Avoid giving users access to commands that allow the user to
1328 run arbitrary commands. Many editors have a restricted mode
1329 where shell escapes are disabled, though sudoedit is a better
1330 solution to running editors via sudo. Due to the large
1331 number of programs that offer shell escapes, restricting
1332 users to the set of programs that do not is often unworkable.
1333
1334 noexec Many systems that support shared libraries have the ability
1335 to override default library functions by pointing an
1336 environment variable (usually LD_PRELOAD) to an alternate
1337 shared library. On such systems, sudo's noexec functionality
1338 can be used to prevent a program run by sudo from executing
1339 any other programs. Note, however, that this applies only to
1340 native dynamically-linked executables. Statically-linked
1341 executables and foreign executables running under binary
1342 emulation are not affected.
1343
1344 To tell whether or not sudo supports noexec, you can run the
1345 following as root:
1346
1347 sudo -V | grep "dummy exec"
1348
1349 If the resulting output contains a line that begins with:
1350
1351 File containing dummy exec functions:
1352
1353 then sudo may be able to replace the exec family of functions
1354 in the standard library with its own that simply return an
1355 error. Unfortunately, there is no foolproof way to know
1356 whether or not noexec will work at compile-time. noexec
1357 should work on SunOS, Solaris, *BSD, Linux, IRIX, Tru64 UNIX,
1358 MacOS X, and HP-UX 11.x. It is known not to work on AIX and
1359 UnixWare. noexec is expected to work on most operating
1360 systems that support the LD_PRELOAD environment variable.
1361 Check your operating system's manual pages for the dynamic
1362 linker (usually ld.so, ld.so.1, dyld, dld.sl, rld, or loader)
1363 to see if LD_PRELOAD is supported.
1364
1365 To enable noexec for a command, use the NOEXEC tag as
1366 documented in the User Specification section above. Here is
1367 that example again:
1368
1369 aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
1370
1371 This allows user aaron to run /usr/bin/more and /usr/bin/vi
1372 with noexec enabled. This will prevent those two commands
1373 from executing other commands (such as a shell). If you are
1374 unsure whether or not your system is capable of supporting
1375 noexec you can always just try it out and see if it works.
1376
1377 Note that restricting shell escapes is not a panacea. Programs running
1378 as root are still capable of many potentially hazardous operations
1379 (such as changing or overwriting files) that could lead to unintended
1380 privilege escalation. In the specific case of an editor, a safer
1381 approach is to give the user permission to run sudoedit.
1382
1384 rsh(1), su(1), fnmatch(3), glob(3), sudo(8), visudo(8)
1385
1387 The sudoers file should always be edited by the visudo command which
1388 locks the file and does grammatical checking. It is imperative that
1389 sudoers be free of syntax errors since sudo will not run with a
1390 syntactically incorrect sudoers file.
1391
1392 When using netgroups of machines (as opposed to users), if you store
1393 fully qualified host name in the netgroup (as is usually the case), you
1394 either need to have the machine's host name be fully qualified as
1395 returned by the hostname command or use the fqdn option in sudoers.
1396
1398 If you feel you have found a bug in sudo, please submit a bug report at
1399 http://www.sudo.ws/sudo/bugs/
1400
1402 Limited free support is available via the sudo-users mailing list, see
1403 http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search
1404 the archives.
1405
1407 sudo is provided ``AS IS'' and any express or implied warranties,
1408 including, but not limited to, the implied warranties of
1409 merchantability and fitness for a particular purpose are disclaimed.
1410 See the LICENSE file distributed with sudo or
1411 http://www.sudo.ws/sudo/license.html for complete details.
1412
1413
1414
14151.7.4 January 12, 2011 SUDOERS(5)