1 Copyright (c) 1994-1996, 1998-2005, 2007
2 Todd C. Miller <Todd.Miller@courtesan.com>
4 Permission to use, copy, modify, and distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 Sponsored in part by the Defense Advanced Research Projects
18 Agency (DARPA) and Air Force Research Laboratory, Air Force
19 Materiel Command, USAF, under agreement number F39502-99-1-0512.
21 $Sudo: sudoers.pod,v 1.95.2.26 2008/02/19 18:13:17 millert Exp $
26 sudoers - list of which users may execute what
30 The I<sudoers> file is composed of two types of entries: aliases
31 (basically variables) and user specifications (which specify who
34 When multiple entries match for a user, they are applied in order.
35 Where there are multiple matches, the last match is used (which is
36 not necessarily the most specific match).
38 The I<sudoers> grammar will be described below in Extended Backus-Naur
39 Form (EBNF). Don't despair if you don't know what EBNF is; it is
40 fairly simple, and the definitions below are annotated.
42 =head2 Quick guide to EBNF
44 EBNF is a concise and exact way of describing the grammar of a language.
45 Each EBNF definition is made up of I<production rules>. E.g.,
47 symbol ::= definition | alternate1 | alternate2 ...
49 Each I<production rule> references others and thus makes up a
50 grammar for the language. EBNF also contains the following
51 operators, which many readers will recognize from regular
52 expressions. Do not, however, confuse them with "wildcard"
53 characters, which have different meanings.
59 Means that the preceding symbol (or group of symbols) is optional.
60 That is, it may appear once or not at all.
64 Means that the preceding symbol (or group of symbols) may appear
69 Means that the preceding symbol (or group of symbols) may appear
74 Parentheses may be used to group symbols together. For clarity,
75 we will use single quotes ('') to designate what is a verbatim character
76 string (as opposed to a symbol name).
80 There are four kinds of aliases: C<User_Alias>, C<Runas_Alias>,
81 C<Host_Alias> and C<Cmnd_Alias>.
83 Alias ::= 'User_Alias' User_Alias (':' User_Alias)* |
84 'Runas_Alias' Runas_Alias (':' Runas_Alias)* |
85 'Host_Alias' Host_Alias (':' Host_Alias)* |
86 'Cmnd_Alias' Cmnd_Alias (':' Cmnd_Alias)*
88 User_Alias ::= NAME '=' User_List
90 Runas_Alias ::= NAME '=' Runas_List
92 Host_Alias ::= NAME '=' Host_List
94 Cmnd_Alias ::= NAME '=' Cmnd_List
96 NAME ::= [A-Z]([a-z][A-Z][0-9]_)*
98 Each I<alias> definition is of the form
100 Alias_Type NAME = item1, item2, ...
102 where I<Alias_Type> is one of C<User_Alias>, C<Runas_Alias>, C<Host_Alias>,
103 or C<Cmnd_Alias>. A C<NAME> is a string of uppercase letters, numbers,
104 and underscore characters ('_'). A C<NAME> B<must> start with an
105 uppercase letter. It is possible to put several alias definitions
106 of the same type on a single line, joined by a colon (':'). E.g.,
108 Alias_Type NAME = item1, item2, item3 : NAME = item4, item5
110 The definitions of what constitutes a valid I<alias> member follow.
115 User ::= '!'* username |
120 A C<User_List> is made up of one or more usernames, system groups
121 (prefixed with '%'), netgroups (prefixed with '+') and other aliases.
122 Each list item may be prefixed with one or more '!' operators.
123 An odd number of '!' operators negate the value of the item; an even
124 number just cancel each other out.
126 Runas_List ::= Runas_User |
127 Runas_User ',' Runas_List
129 Runas_User ::= '!'* username |
135 A C<Runas_List> is similar to a C<User_List> except that it can
136 also contain uids (prefixed with '#') and instead of C<User_Alias>es
137 it can contain C<Runas_Alias>es. Note that usernames and groups
138 are matched as strings. In other words, two users (groups) with
139 the same uid (gid) are considered to be distinct. If you wish to
140 match all usernames with the same uid (e.g.E<nbsp>root and toor), you
141 can use a uid instead (#0 in the example given).
146 Host ::= '!'* hostname |
148 '!'* network(/netmask)? |
152 A C<Host_List> is made up of one or more hostnames, IP addresses,
153 network numbers, netgroups (prefixed with '+') and other aliases.
154 Again, the value of an item may be negated with the '!' operator.
155 If you do not specify a netmask along with the network number,
156 B<sudo> will query each of the local host's network interfaces and,
157 if the network number corresponds to one of the hosts's network
158 interfaces, the corresponding netmask will be used. The netmask
159 may be specified either in standard IP address notation
160 (e.g.E<nbsp>255.255.255.0 or ffff:ffff:ffff:ffff::),
161 or CIDR notation (number of bits, e.g.E<nbsp>24 or 64). A hostname may
162 include shell-style wildcards (see the L<Wildcards> section below),
163 but unless the C<hostname> command on your machine returns the fully
164 qualified hostname, you'll need to use the I<fqdn> option for
165 wildcards to be useful.
170 commandname ::= filename |
174 Cmnd ::= '!'* commandname |
179 A C<Cmnd_List> is a list of one or more commandnames, directories, and other
180 aliases. A commandname is a fully qualified filename which may include
181 shell-style wildcards (see the L<Wildcards> section below). A simple
182 filename allows the user to run the command with any arguments he/she
183 wishes. However, you may also specify command line arguments (including
184 wildcards). Alternately, you can specify C<""> to indicate that the command
185 may only be run B<without> command line arguments. A directory is a
186 fully qualified pathname ending in a '/'. When you specify a directory
187 in a C<Cmnd_List>, the user will be able to run any file within that directory
188 (but not in any subdirectories therein).
190 If a C<Cmnd> has associated command line arguments, then the arguments
191 in the C<Cmnd> must match exactly those given by the user on the command line
192 (or match the wildcards if there are any). Note that the following
193 characters must be escaped with a '\' if they are used in command
194 arguments: ',', ':', '=', '\'. The special command C<"sudoedit">
195 is used to permit a user to run B<sudo> with the B<-e> flag (or
196 as B<sudoedit>). It may take command line arguments just as
197 a normal command does.
201 Certain configuration options may be changed from their default
202 values at runtime via one or more C<Default_Entry> lines. These
203 may affect all users on any host, all users on a specific host, a
204 specific user, or commands being run as a specific user.
206 Default_Type ::= 'Defaults' |
207 'Defaults' '@' Host_List |
208 'Defaults' ':' User_List |
209 'Defaults' '>' Runas_List
211 Default_Entry ::= Default_Type Parameter_List
213 Parameter_List ::= Parameter |
214 Parameter ',' Parameter_List
216 Parameter ::= Parameter '=' Value |
217 Parameter '+=' Value |
218 Parameter '-=' Value |
221 Parameters may be B<flags>, B<integer> values, B<strings>, or B<lists>.
222 Flags are implicitly boolean and can be turned off via the '!'
223 operator. Some integer, string and list parameters may also be
224 used in a boolean context to disable them. Values may be enclosed
225 in double quotes (C<">) when they contain multiple words. Special
226 characters may be escaped with a backslash (C<\>).
228 Lists have two additional assignment operators, C<+=> and C<-=>.
229 These operators are used to add to and delete from a list respectively.
230 It is not an error to use the C<-=> operator to remove an element
231 that does not exist in a list.
233 See L</"SUDOERS OPTIONS"> for a list of supported Defaults parameters.
235 =head2 User Specification
237 User_Spec ::= User_List Host_List '=' Cmnd_Spec_List \
238 (':' Host_List '=' Cmnd_Spec_List)*
240 Cmnd_Spec_List ::= Cmnd_Spec |
241 Cmnd_Spec ',' Cmnd_Spec_List
243 Cmnd_Spec ::= Runas_Spec? Tag_Spec* Cmnd
245 Runas_Spec ::= '(' Runas_List ')'
247 Tag_Spec ::= ('NOPASSWD:' | 'PASSWD:' | 'NOEXEC:' | 'EXEC:' |
248 'SETENV:' | 'NOSETENV:')
250 A B<user specification> determines which commands a user may run
251 (and as what user) on specified hosts. By default, commands are
252 run as B<root>, but this can be changed on a per-command basis.
254 Let's break that down into its constituent parts:
258 A C<Runas_Spec> is simply a C<Runas_List> (as defined above)
259 enclosed in a set of parentheses. If you do not specify a
260 C<Runas_Spec> in the user specification, a default C<Runas_Spec>
261 of B<root> will be used. A C<Runas_Spec> sets the default for
262 commands that follow it. What this means is that for the entry:
264 dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/lprm
266 The user B<dgb> may run F</bin/ls>, F</bin/kill>, and
267 F</usr/bin/lprm> -- but only as B<operator>. E.g.,
269 $ sudo -u operator /bin/ls.
271 It is also possible to override a C<Runas_Spec> later on in an
272 entry. If we modify the entry like so:
274 dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
276 Then user B<dgb> is now allowed to run F</bin/ls> as B<operator>,
277 but F</bin/kill> and F</usr/bin/lprm> as B<root>.
281 A command may have zero or more tags associated with it. There are
282 six possible tag values, C<NOPASSWD>, C<PASSWD>, C<NOEXEC>, C<EXEC>,
283 C<SETENV> and C<NOSETENV>.
284 Once a tag is set on a C<Cmnd>, subsequent C<Cmnd>s in the
285 C<Cmnd_Spec_List>, inherit the tag unless it is overridden by the
286 opposite tag (i.e.: C<PASSWD> overrides C<NOPASSWD> and C<NOEXEC>
289 =head3 NOPASSWD and PASSWD
291 By default, B<sudo> requires that a user authenticate him or herself
292 before running a command. This behavior can be modified via the
293 C<NOPASSWD> tag. Like a C<Runas_Spec>, the C<NOPASSWD> tag sets
294 a default for the commands that follow it in the C<Cmnd_Spec_List>.
295 Conversely, the C<PASSWD> tag can be used to reverse things.
298 ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
300 would allow the user B<ray> to run F</bin/kill>, F</bin/ls>, and
301 F</usr/bin/lprm> as root on the machine rushmore as B<root> without
302 authenticating himself. If we only want B<ray> to be able to
303 run F</bin/kill> without a password the entry would be:
305 ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
307 Note, however, that the C<PASSWD> tag has no effect on users who are
308 in the group specified by the I<exempt_group> option.
310 By default, if the C<NOPASSWD> tag is applied to any of the entries
311 for a user on the current host, he or she will be able to run
312 C<sudo -l> without a password. Additionally, a user may only run
313 C<sudo -v> without a password if the C<NOPASSWD> tag is present
314 for all a user's entries that pertain to the current host.
315 This behavior may be overridden via the verifypw and listpw options.
317 =head3 NOEXEC and EXEC
319 If B<sudo> has been compiled with I<noexec> support and the underlying
320 operating system supports it, the C<NOEXEC> tag can be used to prevent
321 a dynamically-linked executable from running further commands itself.
323 In the following example, user B<aaron> may run F</usr/bin/more>
324 and F</usr/bin/vi> but shell escapes will be disabled.
326 aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
328 See the L<PREVENTING SHELL ESCAPES> section below for more details
329 on how C<NOEXEC> works and whether or not it will work on your system.
331 =head3 SETENV and NOSETENV
333 These tags override the value of the I<setenv> option on a per-command
334 basis. Note that if C<SETENV> has been set for a command, any
335 environment variables set on the command line way are not subject
336 to the restrictions imposed by I<env_check>, I<env_delete>, or
337 I<env_keep>. As such, only trusted users should be allowed to set
338 variables in this manner. If the command matched is B<ALL>, the
339 C<SETENV> tag is implied for that command; this default may
340 be overridden by use of the C<UNSETENV> tag.
344 B<sudo> allows shell-style I<wildcards> (aka meta or glob characters)
345 to be used in pathnames as well as command line arguments in the
346 I<sudoers> file. Wildcard matching is done via the B<POSIX>
347 L<fnmatch(3)> routine. Note that these are I<not> regular expressions.
353 Matches any set of zero or more characters.
357 Matches any single character.
361 Matches any character in the specified range.
365 Matches any character B<not> in the specified range.
369 For any character "x", evaluates to "x". This is used to
370 escape special characters such as: "*", "?", "[", and "}".
374 Note that a forward slash ('/') will B<not> be matched by
375 wildcards used in the pathname. When matching the command
376 line arguments, however, a slash B<does> get matched by
377 wildcards. This is to make a path like:
381 match F</usr/bin/who> but not F</usr/bin/X11/xterm>.
383 =head2 Exceptions to wildcard rules
385 The following exceptions apply to the above rules:
391 If the empty string C<""> is the only command line argument in the
392 I<sudoers> entry it means that command is not allowed to be run
393 with B<any> arguments.
397 =head2 Other special characters and reserved words
399 The pound sign ('#') is used to indicate a comment (unless it is
400 part of a #include directive or unless it occurs in the context of
401 a user name and is followed by one or more digits, in which case
402 it is treated as a uid). Both the comment character and any text
403 after it, up to the end of the line, are ignored.
405 The reserved word B<ALL> is a built-in I<alias> that always causes
406 a match to succeed. It can be used wherever one might otherwise
407 use a C<Cmnd_Alias>, C<User_Alias>, C<Runas_Alias>, or C<Host_Alias>.
408 You should not try to define your own I<alias> called B<ALL> as the
409 built-in alias will be used in preference to your own. Please note
410 that using B<ALL> can be dangerous since in a command context, it
411 allows the user to run B<any> command on the system.
413 An exclamation point ('!') can be used as a logical I<not> operator
414 both in an I<alias> and in front of a C<Cmnd>. This allows one to
415 exclude certain values. Note, however, that using a C<!> in
416 conjunction with the built-in C<ALL> alias to allow a user to
417 run "all but a few" commands rarely works as intended (see SECURITY
420 Long lines can be continued with a backslash ('\') as the last
421 character on the line.
423 Whitespace between elements in a list as well as special syntactic
424 characters in a I<User Specification> ('=', ':', '(', ')') is optional.
426 The following characters must be escaped with a backslash ('\') when
427 used as part of a word (e.g.E<nbsp>a username or hostname):
428 '@', '!', '=', ':', ',', '(', ')', '\'.
430 =head1 SUDOERS OPTIONS
432 B<sudo>'s behavior can be modified by C<Default_Entry> lines, as
433 explained earlier. A list of all supported Defaults parameters,
434 grouped by type, are listed below.
440 =item always_set_home
442 If set, B<sudo> will set the C<HOME> environment variable to the home
443 directory of the target user (which is root unless the B<-u> option is used).
444 This effectively means that the B<-H> flag is always implied.
445 This flag is I<off> by default.
449 If set, users must authenticate themselves via a password (or other
450 means of authentication) before they may run commands. This default
451 may be overridden via the C<PASSWD> and C<NOPASSWD> tags.
452 This flag is I<on> by default.
456 If set, B<visudo> will use the value of the EDITOR or VISUAL
457 environment variables before falling back on the default editor list.
458 Note that this may create a security hole as it allows the user to
459 run any arbitrary command as root without logging. A safer alternative
460 is to place a colon-separated list of editors in the C<editor>
461 variable. B<visudo> will then only use the EDITOR or VISUAL if
462 they match a value specified in C<editor>. This flag is I<@env_editor@> by
467 If set, B<sudo> will reset the environment to only contain the
468 LOGNAME, SHELL, USER, USERNAME and the C<SUDO_*> variables. Any
469 variables in the caller's environment that match the C<env_keep>
470 and C<env_check> lists are then added. The default contents of the
471 C<env_keep> and C<env_check> lists are displayed when B<sudo> is
472 run by root with the I<-V> option. If B<sudo> was compiled with
473 the C<SECURE_PATH> option, its value will be used for the C<PATH>
474 environment variable. This flag is I<on> by default.
478 Set this flag if you want to put fully qualified hostnames in the
479 I<sudoers> file. I.e., instead of myhost you would use myhost.mydomain.edu.
480 You may still use the short form if you wish (and even mix the two).
481 Beware that turning on I<fqdn> requires B<sudo> to make DNS lookups
482 which may make affect B<sudo> performance if DNS stops working (for example
483 if the machine is not plugged into the network). The default behavior for
484 Debian has been modified to minimize the potential of a problem, but there
485 may still be some cases in which lack of working DNS might make sudo work
486 very slowly. Also note that
487 you must use the host's official name as DNS knows it. That is,
488 you may not use a host alias (C<CNAME> entry) due to performance
489 issues and the fact that there is no way to get all aliases from
490 DNS. If your machine's hostname (as returned by the C<hostname>
491 command) is already fully qualified you shouldn't need to set
492 I<fqdn>. This flag is I<@fqdn@> by default.
496 If set, B<sudo> will ignore '.' or '' (current dir) in the C<PATH>
497 environment variable; the C<PATH> itself is not modified. This
498 flag is I<@ignore_dot@> by default. Currently, while it is possible
499 to set I<ignore_dot> in I<sudoers>, its value is not used. This option
500 should be considered read-only (it will be fixed in a future version
503 =item ignore_local_sudoers
505 If set via LDAP, parsing of F<@sysconfdir@/sudoers> will be skipped.
506 This is intended for Enterprises that wish to prevent the usage of local
507 sudoers files so that only LDAP is used. This thwarts the efforts of
508 rogue operators who would attempt to add roles to F<@sysconfdir@/sudoers>.
509 When this option is present, F<@sysconfdir@/sudoers> does not even need to
510 exist. Since this option tells B<sudo> how to behave when no specific LDAP
511 entries have been matched, this sudoOption is only meaningful for the
512 C<cn=defaults> section. This flag is I<off> by default.
516 If set, B<sudo> will insult users when they enter an incorrect
517 password. This flag is I<@insults@> by default.
521 If set, the hostname will be logged in the (non-syslog) B<sudo> log file.
522 This flag is I<off> by default.
526 If set, the four-digit year will be logged in the (non-syslog) B<sudo> log file.
527 This flag is I<off> by default.
529 =item long_otp_prompt
531 When validating with a One Time Password (OPT) scheme such as
532 B<S/Key> or B<OPIE>, a two-line prompt is used to make it easier
533 to cut and paste the challenge to a local window. It's not as
534 pretty as the default but some people find it more convenient. This
535 flag is I<@long_otp_prompt@> by default.
539 Send mail to the I<mailto> user every time a users runs B<sudo>.
540 This flag is I<off> by default.
544 Send mail to the I<mailto> user if the user running B<sudo> does not
545 enter the correct password. This flag is I<off> by default.
549 If set, mail will be sent to the I<mailto> user if the invoking
550 user exists in the I<sudoers> file, but is not allowed to run
551 commands on the current host. This flag is I<@mail_no_host@> by default.
555 If set, mail will be sent to the I<mailto> user if the invoking
556 user is allowed to use B<sudo> but the command they are trying is not
557 listed in their I<sudoers> file entry or is explicitly denied.
558 This flag is I<@mail_no_perms@> by default.
562 If set, mail will be sent to the I<mailto> user if the invoking
563 user is not in the I<sudoers> file. This flag is I<@mail_no_user@>
568 If set, all commands run via B<sudo> will behave as if the C<NOEXEC>
569 tag has been set, unless overridden by a C<EXEC> tag. See the
570 description of I<NOEXEC and EXEC> below as well as the L<PREVENTING SHELL
571 ESCAPES> section at the end of this manual. This flag is I<off> by default.
575 Normally, B<sudo> will tell the user when a command could not be
576 found in their C<PATH> environment variable. Some sites may wish
577 to disable this as it could be used to gather information on the
578 location of executables that the normal user does not have access
579 to. The disadvantage is that if the executable is simply not in
580 the user's C<PATH>, B<sudo> will tell the user that they are not
581 allowed to run it, which can be confusing. This flag is I<@path_info@>
584 =item passprompt_override
586 The password prompt specified by I<passprompt> will normally only
587 be used if the passwod prompt provided by systems such as PAM matches
588 the string "Password:". If I<passprompt_override> is set, I<passprompt>
589 will always be used. This flag is I<off> by default.
591 =item preserve_groups
593 By default B<sudo> will initialize the group vector to the list of
594 groups the target user is in. When I<preserve_groups> is set, the
595 user's existing group vector is left unaltered. The real and
596 effective group IDs, however, are still set to match the target
597 user. This flag is I<off> by default.
601 If set, B<sudo> will only run when the user is logged in to a real
602 tty. This will disallow things like C<"rsh somehost sudo ls"> since
603 L<rsh(1)> does not allocate a tty. Because it is not possible to turn
604 off echo when there is no tty present, some sites may wish to set
605 this flag to prevent a user from entering a visible password. This
606 flag is I<off> by default.
610 If set, root is allowed to run B<sudo> too. Disabling this prevents users
611 from "chaining" B<sudo> commands to get a root shell by doing something
612 like C<"sudo sudo /bin/sh">. Note, however, that turning off I<root_sudo>
613 will also prevent root and from running B<sudoedit>.
614 Disabling I<root_sudo> provides no real additional security; it
615 exists purely for historical reasons.
616 This flag is I<@root_sudo@> by default.
620 If set, B<sudo> will prompt for the root password instead of the password
621 of the invoking user. This flag is I<off> by default.
625 If set, B<sudo> will prompt for the password of the user defined by the
626 I<runas_default> option (defaults to C<@runas_default@>) instead of the
627 password of the invoking user. This flag is I<off> by default.
631 If set and B<sudo> is invoked with the B<-s> flag the C<HOME>
632 environment variable will be set to the home directory of the target
633 user (which is root unless the B<-u> option is used). This effectively
634 makes the B<-s> flag imply B<-H>. This flag is I<off> by default.
638 Normally, B<sudo> will set the C<LOGNAME>, C<USER> and C<USERNAME>
639 environment variables to the name of the target user (usually root
640 unless the B<-u> flag is given). However, since some programs
641 (including the RCS revision control system) use C<LOGNAME> to
642 determine the real identity of the user, it may be desirable to
643 change this behavior. This can be done by negating the set_logname
644 option. Note that if the I<env_reset> option has not been disabled,
645 entries in the I<env_keep> list will override the value of
646 I<set_logname>. This flag is I<off> by default.
650 Allow the user to disable the I<env_reset> option from the command
651 line. Additionally, environment variables set via the command line
652 are not subject to the restrictions imposed by I<env_check>,
653 I<env_delete>, or I<env_keep>. As such, only trusted users should
654 be allowed to set variables in this manner. This flag is I<off>
659 If set and B<sudo> is invoked with no arguments it acts as if the
660 B<-s> flag had been given. That is, it runs a shell as root (the
661 shell is determined by the C<SHELL> environment variable if it is
662 set, falling back on the shell listed in the invoking user's
663 /etc/passwd entry if not). This flag is I<off> by default.
667 Normally, when B<sudo> executes a command the real and effective
668 UIDs are set to the target user (root by default). This option
669 changes that behavior such that the real UID is left as the invoking
670 user's UID. In other words, this makes B<sudo> act as a setuid
671 wrapper. This can be useful on systems that disable some potentially
672 dangerous functionality when a program is run setuid. This option
673 is only effective on systems with either the setreuid() or setresuid()
674 function. This flag is I<off> by default.
678 If set, B<sudo> will prompt for the password of the user specified by
679 the B<-u> flag (defaults to C<root>) instead of the password of the
680 invoking user. Note that this precludes the use of a uid not listed
681 in the passwd database as an argument to the B<-u> flag.
682 This flag is I<off> by default.
686 If set, users must authenticate on a per-tty basis. Normally,
687 B<sudo> uses a directory in the ticket dir with the same name as
688 the user running it. With this flag enabled, B<sudo> will use a
689 file named for the tty the user is logged in on in that directory.
690 This flag is I<@tty_tickets@> by default.
694 If set, B<sudo> will apply the defaults specified for the target user's
695 login class if one exists. Only available if B<sudo> is configured with
696 the --with-logincap option. This flag is I<off> by default.
706 The number of tries a user gets to enter his/her password before
707 B<sudo> logs the failure and exits. The default is C<@passwd_tries@>.
711 B<Integers that can be used in a boolean context>:
717 Number of characters per line for the file log. This value is used
718 to decide when to wrap lines for nicer log files. This has no
719 effect on the syslog log file, only the file log. The default is
720 C<@loglen@> (use 0 or negate the option to disable word wrap).
724 Number of minutes before the B<sudo> password prompt times out.
725 The default is C<@password_timeout@>; set this to C<0> for no password timeout.
727 =item timestamp_timeout
729 Number of minutes that can elapse before B<sudo> will ask for a
730 passwd again. The default is C<@timeout@>. Set this to C<0> to always
731 prompt for a password.
732 If set to a value less than C<0> the user's timestamp will never
733 expire. This can be used to allow users to create or delete their
734 own timestamps via C<sudo -v> and C<sudo -k> respectively.
738 Umask to use when running the command. Negate this option or set
739 it to 0777 to preserve the user's umask. The default is C<@sudo_umask@>.
747 =item badpass_message
749 Message that is displayed if a user enters an incorrect password.
750 The default is C<@badpass_message@> unless insults are enabled.
754 A colon (':') separated list of editors allowed to be used with
755 B<visudo>. B<visudo> will choose the editor that matches the user's
756 EDITOR environment variable if possible, or the first editor in the
757 list that exists and is executable. The default is the path to vi
762 Subject of the mail sent to the I<mailto> user. The escape C<%h>
763 will expand to the hostname of the machine.
764 Default is C<@mailsub@>.
768 Path to a shared library containing dummy versions of the execv(),
769 execve() and fexecve() library functions that just return an error.
770 This is used to implement the I<noexec> functionality on systems that
771 support C<LD_PRELOAD> or its equivalent. Defaults to F<@noexec_file@>.
775 The default prompt to use when asking for a password; can be overridden
776 via the B<-p> option or the C<SUDO_PROMPT> environment variable.
777 The following percent (`C<%>') escapes are supported:
783 expanded to the local hostname including the domain name
784 (on if the machine's hostname is fully qualified or the I<fqdn>
789 expanded to the local hostname without the domain name
793 expanded to the user whose password is being asked for (respects the
794 I<rootpw>, I<targetpw> and I<runaspw> flags in I<sudoers>)
798 expanded to the login name of the user the command will
799 be run as (defaults to root)
803 expanded to the invoking user's login name
807 two consecutive C<%> characters are collapsed into a single C<%> character
811 The default value is C<@passprompt@>.
815 The default SELinux role to use when constructing a new security
816 context to run the command. The default role may be overridden on
817 a per-command basis in I<sudoers> or via command line options.
818 This option is only available whe B<sudo> is built with SELinux support.
822 The default user to run commands as if the B<-u> flag is not specified
823 on the command line. This defaults to C<@runas_default@>.
824 Note that if I<runas_default> is set it B<must> occur before
825 any C<Runas_Alias> specifications.
829 Syslog priority to use when user authenticates unsuccessfully.
830 Defaults to C<@badpri@>.
834 Syslog priority to use when user authenticates successfully.
835 Defaults to C<@goodpri@>.
839 The directory in which B<sudo> stores its timestamp files.
840 The default is F<@timedir@>.
844 The owner of the timestamp directory and the timestamps stored therein.
845 The default is C<root>.
849 The default SELinux type to use when constructing a new security
850 context to run the command. The default type may be overridden on
851 a per-command basis in I<sudoers> or via command line options.
852 This option is only available whe B<sudo> is built with SELinux support.
856 B<Strings that can be used in a boolean context>:
862 Users in this group are exempt from password and PATH requirements.
863 This is not set by default.
867 This option controls when a short lecture will be printed along with
868 the password prompt. It has the following possible values:
874 Always lecture the user.
878 Never lecture the user.
882 Only lecture the user the first time they run B<sudo>.
886 If no value is specified, a value of I<once> is implied.
887 Negating the option results in a value of I<never> being used.
888 The default value is I<@lecture@>.
892 Path to a file containing an alternate B<sudo> lecture that will
893 be used in place of the standard lecture if the named file exists.
894 By default, B<sudo> uses a built-in lecture.
898 This option controls when a password will be required when a
899 user runs B<sudo> with the B<-l> flag. It has the following possible values:
905 All the user's I<sudoers> entries for the current host must have
906 the C<NOPASSWD> flag set to avoid entering a password.
910 The user must always enter a password to use the B<-l> flag.
914 At least one of the user's I<sudoers> entries for the current host
915 must have the C<NOPASSWD> flag set to avoid entering a password.
919 The user need never enter a password to use the B<-l> flag.
923 If no value is specified, a value of I<any> is implied.
924 Negating the option results in a value of I<never> being used.
925 The default value is I<any>.
929 Path to the B<sudo> log file (not the syslog log file). Setting a path
930 turns on logging to a file; negating this option turns it off.
931 By default, B<sudo> logs via syslog.
935 Flags to use when invoking mailer. Defaults to B<-t>.
939 Path to mail program used to send warning mail.
940 Defaults to the path to sendmail found at configure time.
944 Address to send warning and error mail to. The address should
945 be enclosed in double quotes (C<">) to protect against B<sudo>
946 interpreting the C<@> sign. Defaults to C<@mailto@>.
950 Syslog facility if syslog is being used for logging (negate to
951 disable syslog logging). Defaults to C<@logfac@>.
955 This option controls when a password will be required when a user runs
956 B<sudo> with the B<-v> flag. It has the following possible values:
962 All the user's I<sudoers> entries for the current host must have
963 the C<NOPASSWD> flag set to avoid entering a password.
967 The user must always enter a password to use the B<-v> flag.
971 At least one of the user's I<sudoers> entries for the current host
972 must have the C<NOPASSWD> flag set to avoid entering a password.
976 The user need never enter a password to use the B<-v> flag.
980 If no value is specified, a value of I<all> is implied.
981 Negating the option results in a value of I<never> being used.
982 The default value is I<all>.
986 B<Lists that can be used in a boolean context>:
992 Like I<env_keep>, but listed environment variables are taken from the user's environment if
993 the variable's value does B<not> contain C<%> or C</> characters. This can
994 be used to guard against printf-style format vulnerabilities in
995 poorly-written programs. The argument may be a double-quoted,
996 space-separated list or a single value without double-quotes. The
997 list can be replaced, added to, deleted from, or disabled by using
998 the C<=>, C<+=>, C<-=>, and C<!> operators respectively. Regardless
999 of whether the C<env_reset> option is enabled or disabled, variables
1000 specified by C<env_check> will be preserved in the environment if
1001 they pass the aforementioned check. The default list of environment
1002 variables to check is displayed when B<sudo> is run by root with
1008 Not effective due to security issues: only variables listed in
1009 I<env_keep> or I<env_check> can be passed through B<sudo>!
1011 The argument may be a double-quoted, space-separated list or a
1012 single value without double-quotes. The list can be replaced, added
1013 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
1014 C<!> operators respectively. The default list of environment
1015 variables to remove is displayed when B<sudo> is run by root with the
1016 I<-V> option. Note that many operating systems will remove potentially
1017 dangerous variables from the environment of any setuid process (such
1022 Environment variables to be preserved in the user's environment.
1023 This allows fine-grained
1024 control over the environment B<sudo>-spawned processes will receive.
1025 The argument may be a double-quoted, space-separated list or a
1026 single value without double-quotes. The list can be replaced, added
1027 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
1028 C<!> operators respectively. The default list of variables to keep
1029 is displayed when B<sudo> is run by root with the I<-V> option.
1033 When logging via L<syslog(3)>, B<sudo> accepts the following values
1034 for the syslog facility (the value of the B<syslog> Parameter):
1035 B<authpriv> (if your OS supports it), B<auth>, B<daemon>, B<user>,
1036 B<local0>, B<local1>, B<local2>, B<local3>, B<local4>, B<local5>,
1037 B<local6>, and B<local7>. The following syslog priorities are
1038 supported: B<alert>, B<crit>, B<debug>, B<emerg>, B<err>, B<info>,
1039 B<notice>, and B<warning>.
1045 =item F<@sysconfdir@/sudoers>
1047 List of who can run what
1053 =item F</etc/netgroup>
1055 List of network groups
1061 Since the I<sudoers> file is parsed in a single pass, order is
1062 important. In general, you should structure I<sudoers> such that
1063 the C<Host_Alias>, C<User_Alias>, and C<Cmnd_Alias> specifications
1064 come first, followed by any C<Default_Entry> lines, and finally the
1065 C<Runas_Alias> and user specifications. The basic rule of thumb
1066 is that you cannot reference an Alias that has not already been defined.
1068 Below are example I<sudoers> entries. Admittedly, some of
1069 these are a bit contrived. First, we allow a few environment
1070 variables to pass and then define our I<aliases>:
1072 # Run X applications through sudo; HOME is used to find .Xauthority file
1073 # Note that some programs may use HOME for other purposes too and
1074 # this may lead to privilege escalation!
1075 Defaults env_keep = "DISPLAY HOME"
1077 # User alias specification
1078 User_Alias FULLTIMERS = millert, mikef, dowdy
1079 User_Alias PARTTIMERS = bostley, jwfox, crawl
1080 User_Alias WEBMASTERS = will, wendy, wim
1082 # Runas alias specification
1083 Runas_Alias OP = root, operator
1084 Runas_Alias DB = oracle, sybase
1086 # Host alias specification
1087 Host_Alias SPARC = bigtime, eclipse, moet, anchor :\
1088 SGI = grolsch, dandelion, black :\
1089 ALPHA = widget, thalamus, foobar :\
1090 HPPA = boa, nag, python
1091 Host_Alias CUNETS = 128.138.0.0/255.255.0.0
1092 Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
1093 Host_Alias SERVERS = master, mail, www, ns
1094 Host_Alias CDROM = orion, perseus, hercules
1096 # Cmnd alias specification
1097 Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
1098 /usr/sbin/restore, /usr/sbin/rrestore
1099 Cmnd_Alias KILL = /usr/bin/kill
1100 Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm
1101 Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown
1102 Cmnd_Alias HALT = /usr/sbin/halt
1103 Cmnd_Alias REBOOT = /usr/sbin/reboot
1104 Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
1105 /usr/local/bin/tcsh, /usr/bin/rsh, \
1107 Cmnd_Alias SU = /usr/bin/su
1108 Cmnd_Alias PAGERS = /usr/bin/more, /usr/bin/pg, /usr/bin/less
1110 Here we override some of the compiled in default values. We want
1111 B<sudo> to log via L<syslog(3)> using the I<auth> facility in all
1112 cases. We don't want to subject the full time staff to the B<sudo>
1113 lecture, user B<millert> need not give a password, and we don't
1114 want to reset the C<LOGNAME>, C<USER> or C<USERNAME> environment
1115 variables when running commands as root. Additionally, on the
1116 machines in the I<SERVERS> C<Host_Alias>, we keep an additional
1117 local log file and make sure we log the year in each log line since
1118 the log entries will be kept around for several years. Lastly, we
1119 disable shell escapes for the commands in the PAGERS C<Cmnd_Alias>
1120 (F</usr/bin/more>, F</usr/bin/pg> and F</usr/bin/less>).
1122 # Override built-in defaults
1123 Defaults syslog=auth
1124 Defaults>root !set_logname
1125 Defaults:FULLTIMERS !lecture
1126 Defaults:millert !authenticate
1127 Defaults@SERVERS log_year, logfile=/var/log/sudo.log
1128 Defaults!PAGERS noexec
1130 The I<User specification> is the part that actually determines who may
1133 root ALL = (ALL) ALL
1134 %wheel ALL = (ALL) ALL
1136 We let B<root> and any user in group B<wheel> run any command on any
1139 FULLTIMERS ALL = NOPASSWD: ALL
1141 Full time sysadmins (B<millert>, B<mikef>, and B<dowdy>) may run any
1142 command on any host without authenticating themselves.
1144 PARTTIMERS ALL = ALL
1146 Part time sysadmins (B<bostley>, B<jwfox>, and B<crawl>) may run any
1147 command on any host but they must authenticate themselves first
1148 (since the entry lacks the C<NOPASSWD> tag).
1152 The user B<jack> may run any command on the machines in the I<CSNETS> alias
1153 (the networks C<128.138.243.0>, C<128.138.204.0>, and C<128.138.242.0>).
1154 Of those networks, only C<128.138.204.0> has an explicit netmask (in
1155 CIDR notation) indicating it is a class C network. For the other
1156 networks in I<CSNETS>, the local machine's netmask will be used
1161 The user B<lisa> may run any command on any host in the I<CUNETS> alias
1162 (the class B network C<128.138.0.0>).
1164 operator ALL = DUMPS, KILL, SHUTDOWN, HALT, REBOOT, PRINTING,\
1165 sudoedit /etc/printcap, /usr/oper/bin/
1167 The B<operator> user may run commands limited to simple maintenance.
1168 Here, those are commands related to backups, killing processes, the
1169 printing system, shutting down the system, and any commands in the
1170 directory F</usr/oper/bin/>.
1172 joe ALL = /usr/bin/su operator
1174 The user B<joe> may only L<su(1)> to operator.
1176 pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root
1178 The user B<pete> is allowed to change anyone's password except for
1179 root on the I<HPPA> machines. Note that this assumes L<passwd(1)>
1180 does not take multiple usernames on the command line.
1182 bob SPARC = (OP) ALL : SGI = (OP) ALL
1184 The user B<bob> may run anything on the I<SPARC> and I<SGI> machines
1185 as any user listed in the I<OP> C<Runas_Alias> (B<root> and B<operator>).
1189 The user B<jim> may run any command on machines in the I<biglab> netgroup.
1190 B<sudo> knows that "biglab" is a netgroup due to the '+' prefix.
1192 +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
1194 Users in the B<secretaries> netgroup need to help manage the printers
1195 as well as add and remove users, so they are allowed to run those
1196 commands on all machines.
1198 fred ALL = (DB) NOPASSWD: ALL
1200 The user B<fred> can run commands as any user in the I<DB> C<Runas_Alias>
1201 (B<oracle> or B<sybase>) without giving a password.
1203 john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
1205 On the I<ALPHA> machines, user B<john> may su to anyone except root
1206 but he is not allowed to give L<su(1)> any flags.
1208 jen ALL, !SERVERS = ALL
1210 The user B<jen> may run any command on any machine except for those
1211 in the I<SERVERS> C<Host_Alias> (master, mail, www and ns).
1213 jill SERVERS = /usr/bin/, !SU, !SHELLS
1215 For any machine in the I<SERVERS> C<Host_Alias>, B<jill> may run
1216 any commands in the directory F</usr/bin/> except for those commands
1217 belonging to the I<SU> and I<SHELLS> C<Cmnd_Aliases>.
1219 steve CSNETS = (operator) /usr/local/op_commands/
1221 The user B<steve> may run any command in the directory /usr/local/op_commands/
1222 but only as user operator.
1224 matt valkyrie = KILL
1226 On his personal workstation, valkyrie, B<matt> needs to be able to
1227 kill hung processes.
1229 WEBMASTERS www = (www) ALL, (root) /usr/bin/su www
1231 On the host www, any user in the I<WEBMASTERS> C<User_Alias> (will,
1232 wendy, and wim), may run any command as user www (which owns the
1233 web pages) or simply L<su(1)> to www.
1235 ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\
1236 /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
1238 Any user may mount or unmount a CD-ROM on the machines in the CDROM
1239 C<Host_Alias> (orion, perseus, hercules) without entering a password.
1240 This is a bit tedious for users to type, so it is a prime candidate
1241 for encapsulating in a shell script.
1243 =head1 SECURITY NOTES
1245 It is generally not effective to "subtract" commands from C<ALL>
1246 using the '!' operator. A user can trivially circumvent this
1247 by copying the desired command to a different name and then
1248 executing that. For example:
1250 bill ALL = ALL, !SU, !SHELLS
1252 Doesn't really prevent B<bill> from running the commands listed in
1253 I<SU> or I<SHELLS> since he can simply copy those commands to a
1254 different name, or use a shell escape from an editor or other
1255 program. Therefore, these kind of restrictions should be considered
1256 advisory at best (and reinforced by policy).
1258 =head1 PREVENTING SHELL ESCAPES
1260 Once B<sudo> executes a program, that program is free to do whatever
1261 it pleases, including run other programs. This can be a security
1262 issue since it is not uncommon for a program to allow shell escapes,
1263 which lets a user bypass B<sudo>'s access control and logging.
1264 Common programs that permit shell escapes include shells (obviously),
1265 editors, paginators, mail and terminal programs.
1267 There are two basic approaches to this problem:
1273 Avoid giving users access to commands that allow the user to run
1274 arbitrary commands. Many editors have a restricted mode where shell
1275 escapes are disabled, though B<sudoedit> is a better solution to
1276 running editors via B<sudo>. Due to the large number of programs that
1277 offer shell escapes, restricting users to the set of programs that
1278 do not if often unworkable.
1282 Many systems that support shared libraries have the ability to
1283 override default library functions by pointing an environment
1284 variable (usually C<LD_PRELOAD>) to an alternate shared library.
1285 On such systems, B<sudo>'s I<noexec> functionality can be used to
1286 prevent a program run by B<sudo> from executing any other programs.
1287 Note, however, that this applies only to native dynamically-linked
1288 executables. Statically-linked executables and foreign executables
1289 running under binary emulation are not affected.
1291 To tell whether or not B<sudo> supports I<noexec>, you can run
1292 the following as root:
1294 sudo -V | grep "dummy exec"
1296 If the resulting output contains a line that begins with:
1298 File containing dummy exec functions:
1300 then B<sudo> may be able to replace the exec family of functions
1301 in the standard library with its own that simply return an error.
1302 Unfortunately, there is no foolproof way to know whether or not
1303 I<noexec> will work at compile-time. I<noexec> should work on
1304 SunOS, Solaris, *BSD, Linux, IRIX, Tru64 UNIX, MacOS X, and HP-UX
1305 11.x. It is known B<not> to work on AIX and UnixWare. I<noexec>
1306 is expected to work on most operating systems that support the
1307 C<LD_PRELOAD> environment variable. Check your operating system's
1308 manual pages for the dynamic linker (usually ld.so, ld.so.1, dyld,
1309 dld.sl, rld, or loader) to see if C<LD_PRELOAD> is supported.
1311 To enable I<noexec> for a command, use the C<NOEXEC> tag as documented
1312 in the User Specification section above. Here is that example again:
1314 aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
1316 This allows user B<aaron> to run F</usr/bin/more> and F</usr/bin/vi>
1317 with I<noexec> enabled. This will prevent those two commands from
1318 executing other commands (such as a shell). If you are unsure
1319 whether or not your system is capable of supporting I<noexec> you
1320 can always just try it out and see if it works.
1324 Note that restricting shell escapes is not a panacea. Programs
1325 running as root are still capable of many potentially hazardous
1326 operations (such as changing or overwriting files) that could lead
1327 to unintended privilege escalation. In the specific case of an
1328 editor, a safer approach is to give the user permission to run
1333 L<rsh(1)>, L<su(1)>, L<fnmatch(3)>, L<sudo(8)>, L<visudo(8)>
1337 The I<sudoers> file should B<always> be edited by the B<visudo>
1338 command which locks the file and does grammatical checking. It is
1339 imperative that I<sudoers> be free of syntax errors since B<sudo>
1340 will not run with a syntactically incorrect I<sudoers> file.
1342 When using netgroups of machines (as opposed to users), if you
1343 store fully qualified hostnames in the netgroup (as is usually the
1344 case), you either need to have the machine's hostname be fully qualified
1345 as returned by the C<hostname> command or use the I<fqdn> option in
1350 If you feel you have found a bug in B<sudo>, please submit a bug report
1351 at http://www.sudo.ws/sudo/bugs/
1355 Limited free support is available via the sudo-users mailing list,
1356 see http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or
1357 search the archives.
1361 B<sudo> is provided ``AS IS'' and any express or implied warranties,
1362 including, but not limited to, the implied warranties of merchantability
1363 and fitness for a particular purpose are disclaimed. See the LICENSE
1364 file distributed with B<sudo> or http://www.sudo.ws/sudo/license.html
1365 for complete details.