2 Copyright (c) 1994-1996,1998-2001 Todd C. Miller <Todd.Miller@courtesan.com>
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products
17 derived from this software without specific prior written permission
20 4. Products derived from this software may not be called "Sudo" nor
21 may "Sudo" appear in their names without specific prior written
22 permission from the author.
24 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27 THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 $Sudo: sudoers.pod,v 1.63 2002/01/13 18:36:44 millert Exp $
40 sudoers - list of which users may execute what
44 The I<sudoers> file is composed of two types of entries:
45 aliases (basically variables) and user specifications
46 (which specify who may run what). The grammar of I<sudoers>
47 will be described below in Extended Backus-Naur Form (EBNF).
48 Don't despair if you don't know what EBNF is; it is fairly
49 simple, and the definitions below are annotated.
51 =head2 Quick guide to EBNF
53 EBNF is a concise and exact way of describing the grammar of a language.
54 Each EBNF definition is made up of I<production rules>. E.g.,
56 symbol ::= definition | alternate1 | alternate2 ...
58 Each I<production rule> references others and thus makes up a
59 grammar for the language. EBNF also contains the following
60 operators, which many readers will recognize from regular
61 expressions. Do not, however, confuse them with "wildcard"
62 characters, which have different meanings.
68 Means that the preceding symbol (or group of symbols) is optional.
69 That is, it may appear once or not at all.
73 Means that the preceding symbol (or group of symbols) may appear
78 Means that the preceding symbol (or group of symbols) may appear
83 Parentheses may be used to group symbols together. For clarity,
84 we will use single quotes ('') to designate what is a verbatim character
85 string (as opposed to a symbol name).
89 There are four kinds of aliases: C<User_Alias>, C<Runas_Alias>,
90 C<Host_Alias> and C<Cmnd_Alias>.
92 Alias ::= 'User_Alias' User_Alias (':' User_Alias)* |
93 'Runas_Alias' Runas_Alias (':' Runas_Alias)* |
94 'Host_Alias' Host_Alias (':' Host_Alias)* |
95 'Cmnd_Alias' Cmnd_Alias (':' Cmnd_Alias)*
97 User_Alias ::= NAME '=' User_List
99 Runas_Alias ::= NAME '=' Runas_List
101 Host_Alias ::= NAME '=' Host_List
103 Cmnd_Alias ::= NAME '=' Cmnd_List
105 NAME ::= [A-Z]([A-Z][0-9]_)*
107 Each I<alias> definition is of the form
109 Alias_Type NAME = item1, item2, ...
111 where I<Alias_Type> is one of C<User_Alias>, C<Runas_Alias>, C<Host_Alias>,
112 or C<Cmnd_Alias>. A C<NAME> is a string of uppercase letters, numbers,
113 and the underscore characters ('_'). A C<NAME> B<must> start with an
114 uppercase letter. It is possible to put several alias definitions
115 of the same type on a single line, joined by a colon (':'). E.g.,
117 Alias_Type NAME = item1, item2, item3 : NAME = item4, item5
119 The definitions of what constitutes a valid I<alias> member follow.
124 User ::= '!'* username |
129 A C<User_List> is made up of one or more usernames, uids
130 (prefixed with '#'), System groups (prefixed with '%'),
131 netgroups (prefixed with '+') and other aliases. Each list
132 item may be prefixed with one or more '!' operators. An odd number
133 of '!' operators negate the value of the item; an even number
134 just cancel each other out.
136 Runas_List ::= Runas_User |
137 Runas_User ',' Runas_List
139 Runas_User ::= '!'* username |
145 A C<Runas_List> is similar to a C<User_List> except that it can
146 also contain uids (prefixed with '#') and instead of C<User_Alias>es
147 it can contain C<Runas_Alias>es.
152 Host ::= '!'* hostname |
154 '!'* network(/netmask)? |
158 A C<Host_List> is made up of one or more hostnames, IP addresses,
159 network numbers, netgroups (prefixed with '+') and other aliases.
160 Again, the value of an item may be negated with the '!' operator.
161 If you do not specify a netmask with a network number, the netmask
162 of the host's ethernet interface(s) will be used when matching.
163 The netmask may be specified either in dotted quad notation (e.g.
164 255.255.255.0) or CIDR notation (number of bits, e.g. 24). A hostname
165 may include shell-style wildcards (see `Wildcards' section below),
166 but unless the C<hostname> command on your machine returns the fully
167 qualified hostname, you'll need to use the I<fqdn> option for wildcards
173 commandname ::= filename |
177 Cmnd ::= '!'* commandname |
181 A C<Cmnd_List> is a list of one or more commandnames, directories, and other
182 aliases. A commandname is a fully qualified filename which may include
183 shell-style wildcards (see `Wildcards' section below). A simple
184 filename allows the user to run the command with any arguments he/she
185 wishes. However, you may also specify command line arguments (including
186 wildcards). Alternately, you can specify C<""> to indicate that the command
187 may only be run B<without> command line arguments. A directory is a
188 fully qualified pathname ending in a '/'. When you specify a directory
189 in a C<Cmnd_List>, the user will be able to run any file within that directory
190 (but not in any subdirectories therein).
192 If a C<Cmnd> has associated command line arguments, then the arguments
193 in the C<Cmnd> must match exactly those given by the user on the command line
194 (or match the wildcards if there are any). Note that the following
195 characters must be escaped with a '\' if they are used in command
196 arguments: ',', ':', '=', '\'.
200 Certain configuration options may be changed from their default
201 values at runtime via one or more C<Default_Entry> lines. These
202 may affect all users on any host, all users on a specific host,
203 or just a specific user. When multiple entries match, they are
204 applied in order. Where there are conflicting values, the last
205 value on a matching line takes effect.
207 Default_Type ::= 'Defaults' ||
208 'Defaults' ':' User ||
211 Default_Entry ::= Default_Type Parameter_List
213 Parameter ::= Parameter '=' Value ||
214 Parameter '+=' Value ||
215 Parameter '-=' Value ||
218 Parameters may be B<flags>, B<integer> values, B<strings>, or B<lists>.
219 Flags are implicitly boolean and can be turned off via the '!'
220 operator. Some integer, string and list parameters may also be
221 used in a boolean context to disable them. Values may be enclosed
222 in double quotes (C<">) when they contain multiple words. Special
223 characters may be escaped with a backslash (C<\>).
225 Lists have two additional assignment operators, C<+=> and C<-=>.
226 These operators are used to add to and delete from a list respectively.
227 It is not an error to use the C<-=> operator to remove an element
228 that does not exist in a list.
230 Note that since the I<sudoers> file is parsed in order the best place
231 to put the Defaults section is after the Host, User, and Cmnd aliases
232 but before the user specifications.
238 =item long_otp_prompt
240 When validating with a One Time Password scheme (B<S/Key> or B<OPIE>),
241 a two-line prompt is used to make it easier to cut and paste the
242 challenge to a local window. It's not as pretty as the default but
243 some people find it more convenient. This flag is I<@long_otp_prompt@>
248 If set, B<sudo> will ignore '.' or '' (current dir) in the C<PATH>
249 environment variable; the C<PATH> itself is not modified. This
250 flag is I<@ignore_dot@> by default.
254 Send mail to the I<mailto> user every time a users runs B<sudo>.
255 This flag is I<off> by default.
259 Send mail to the I<mailto> user if the user running sudo does not
260 enter the correct password. This flag is I<off> by default.
264 If set, mail will be sent to the I<mailto> user if the invoking
265 user is not in the I<sudoers> file. This flag is I<@mail_no_user@>
270 If set, mail will be sent to the I<mailto> user if the invoking
271 user exists in the I<sudoers> file, but is not allowed to run
272 commands on the current host. This flag is I<@mail_no_host@> by default.
276 If set, mail will be sent to the I<mailto> user if the invoking
277 user allowed to use B<sudo> but the command they are trying is not
278 listed in their I<sudoers> file entry. This flag is I<@mail_no_perms@>
283 If set, users must authenticate on a per-tty basis. Normally,
284 B<sudo> uses a directory in the ticket dir with the same name as
285 the user running it. With this flag enabled, B<sudo> will use a
286 file named for the tty the user is logged in on in that directory.
287 This flag is I<@tty_tickets@> by default.
291 If set, a user will receive a short lecture the first time he/she
292 runs B<sudo>. This flag is I<@lecture@> by default.
296 If set, users must authenticate themselves via a password (or other
297 means of authentication) before they may run commands. This default
298 may be overridden via the C<PASSWD> and C<NOPASSWD> tags.
299 This flag is I<on> by default.
303 If set, root is allowed to run B<sudo> too. Disabling this prevents users
304 from "chaining" B<sudo> commands to get a root shell by doing something
305 like C<"sudo sudo /bin/sh">.
306 This flag is I<on> by default.
310 If set, the hostname will be logged in the (non-syslog) B<sudo> log file.
311 This flag is I<off> by default.
315 If set, the four-digit year will be logged in the (non-syslog) B<sudo> log file.
316 This flag is I<off> by default.
320 If set and B<sudo> is invoked with no arguments it acts as if the
321 B<-s> flag had been given. That is, it runs a shell as root (the
322 shell is determined by the C<SHELL> environment variable if it is
323 set, falling back on the shell listed in the invoking user's
324 /etc/passwd entry if not). This flag is I<off> by default.
328 If set and B<sudo> is invoked with the B<-s> flag the C<HOME>
329 environment variable will be set to the home directory of the target
330 user (which is root unless the B<-u> option is used). This effectively
331 makes the B<-s> flag imply B<-H>. This flag is I<off> by default.
333 =item always_set_home
335 If set, B<sudo> will set the C<HOME> environment variable to the home
336 directory of the target user (which is root unless the B<-u> option is used).
337 This effectively means that the B<-H> flag is always implied.
338 This flag is I<off> by default.
342 Normally, B<sudo> will tell the user when a command could not be
343 found in their C<PATH> environment variable. Some sites may wish
344 to disable this as it could be used to gather information on the
345 location of executables that the normal user does not have access
346 to. The disadvantage is that if the executable is simply not in
347 the user's C<PATH>, B<sudo> will tell the user that they are not
348 allowed to run it, which can be confusing. This flag is I<off> by
351 =item preserve_groups
353 By default B<sudo> will initialize the group vector to the list of
354 groups the target user is in. When I<preserve_groups> is set, the
355 user's existing group vector is left unaltered. The real and
356 effective group IDs, however, are still set to match the target
357 user. This flag is I<off> by default.
361 Set this flag if you want to put fully qualified hostnames in the
362 I<sudoers> file. I.e.: instead of myhost you would use myhost.mydomain.edu.
363 You may still use the short form if you wish (and even mix the two).
364 Beware that turning on I<fqdn> requires B<sudo> to make DNS lookups
365 which may make B<sudo> unusable if DNS stops working (for example
366 if the machine is not plugged into the network). Also note that
367 you must use the host's official name as DNS knows it. That is,
368 you may not use a host alias (C<CNAME> entry) due to performance
369 issues and the fact that there is no way to get all aliases from
370 DNS. If your machine's hostname (as returned by the C<hostname>
371 command) is already fully qualified you shouldn't need to set
372 I<fqdn>. This flag is I<@fqdn@> by default.
376 If set, B<sudo> will insult users when they enter an incorrect
377 password. This flag is I<@insults@> by default.
381 If set, B<sudo> will only run when the user is logged in to a real
382 tty. This will disallow things like C<"rsh somehost sudo ls"> since
383 rsh(1) does not allocate a tty. Because it is not possible to turn
384 of echo when there is no tty present, some sites may with to set
385 this flag to prevent a user from entering a visible password. This
386 flag is I<off> by default.
390 If set, B<visudo> will use the value of the EDITOR or VISUAL
391 environment variables before falling back on the default editor list.
392 Note that this may create a security hole as it allows the user to
393 run any arbitrary command as root without logging. A safer alternative
394 is to place a colon-separated list of editors in the C<editor>
395 variable. B<visudo> will then only use the EDITOR or VISUAL if
396 they match a value specified in C<editor>. This flag is C<@env_editor@> by
401 If set, B<sudo> will prompt for the root password instead of the password
402 of the invoking user. This flag is I<off> by default.
406 If set, B<sudo> will prompt for the password of the user defined by the
407 I<runas_default> option (defaults to C<root>) instead of the password
408 of the invoking user. This flag is I<off> by default.
412 If set, B<sudo> will prompt for the password of the user specified by
413 the B<-u> flag (defaults to C<root>) instead of the password of the
414 invoking user. This flag is I<off> by default.
418 Normally, B<sudo> will set the C<LOGNAME> and C<USER> environment variables
419 to the name of the target user (usually root unless the B<-u> flag is given).
420 However, since some programs (including the RCS revision control system)
421 use C<LOGNAME> to determine the real identity of the user, it may be desirable
422 to change this behavior. This can be done by negating the set_logname option.
426 Normally, when B<sudo> executes a command the real and effective
427 UIDs are set to the target user (root by default). This option
428 changes that behavior such that the real UID is left as the invoking
429 user's UID. In other words, this makes B<sudo> act as a setuid
430 wrapper. This can be useful on systems that disable some potentially
431 dangerous functionality when a program is run setuid. Note, however,
432 that this means that sudo will run with the real uid of the invoking
433 user which may allow that user to kill B<sudo> before it can log a
434 failure, depending on how your OS defines the interaction between
435 signals and setuid processes.
439 If set, B<sudo> will reset the environment to only contain the
440 following variables: C<HOME>, C<LOGNAME>, C<PATH>, C<SHELL>, C<TERM>,
441 and C<USER> (in addition to the C<SUDO_*> variables).
442 Of these, only C<TERM> is copied unaltered from the old environment.
443 The other variables are set to default values (possibly modified
444 by the value of the I<set_logname> option). If B<sudo> was compiled
445 with the C<SECURE_PATH> option, its value will be used for the C<PATH>
446 environment variable.
447 Other variables may be preserved with the I<env_keep> option.
451 If set, B<sudo> will apply the defaults specified for the target user's
452 login class if one exists. Only available if B<sudo> is configured with
453 the --with-logincap option. This flag is I<off> by default.
463 The number of tries a user gets to enter his/her password before
464 B<sudo> logs the failure and exits. The default is C<@passwd_tries@>.
468 B<Integers that can be used in a boolean context>:
474 Number of characters per line for the file log. This value is used
475 to decide when to wrap lines for nicer log files. This has no
476 effect on the syslog log file, only the file log. The default is
477 C<@loglen@> (use 0 or negate the option to disable word wrap).
479 =item timestamp_timeout
481 Number of minutes that can elapse before B<sudo> will ask for a
482 passwd again. The default is C<@timeout@>. Set this to C<0> to always
483 prompt for a password.
484 If set to a value less than C<0> the user's timestamp will never
485 expire. This can be used to allow users to create or delete their
486 own timestamps via C<sudo -v> and C<sudo -k> respectively.
490 Number of minutes before the B<sudo> password prompt times out.
491 The default is C<@password_timeout@>, set this to C<0> for no password timeout.
495 Umask to use when running the command. Negate this option or set
496 it to 0777 to preserve the user's umask. The default is C<@sudo_umask@>.
506 Subject of the mail sent to the I<mailto> user. The escape C<%h>
507 will expand to the hostname of the machine.
508 Default is C<@mailsub@>.
510 =item badpass_message
512 Message that is displayed if a user enters an incorrect password.
513 The default is C<@badpass_message@> unless insults are enabled.
517 The directory in which B<sudo> stores its timestamp files.
518 The default is F<@timedir@>.
522 The default prompt to use when asking for a password; can be overridden
523 via the B<-p> option or the C<SUDO_PROMPT> environment variable. Supports
524 two escapes: "%u" expands to the user's login name and "%h" expands
525 to the local hostname. The default value is C<@passprompt@>.
529 The default user to run commands as if the B<-u> flag is not specified
530 on the command line. This defaults to C<@runas_default@>.
534 Syslog priority to use when user authenticates successfully.
535 Defaults to C<@goodpri@>.
539 Syslog priority to use when user authenticates unsuccessfully.
540 Defaults to C<@badpri@>.
544 A colon (':') separated list of editors allowed to be used with
545 B<visudo>. B<visudo> will choose the editor that matches the user's
546 USER environment variable if possible, or the first editor in the
547 list that exists and is executable. The default is the path to vi
552 B<Strings that can be used in a boolean context>:
558 Path to the B<sudo> log file (not the syslog log file). Setting a path
559 turns on logging to a file; negating this option turns it off.
563 Syslog facility if syslog is being used for logging (negate to
564 disable syslog logging). Defaults to C<@logfac@>.
568 Path to mail program used to send warning mail.
569 Defaults to the path to sendmail found at configure time.
573 Flags to use when invoking mailer. Defaults to B<-t>.
577 Address to send warning and error mail to. The address should
578 be enclosed in double quotes (C<">) to protect against sudo
579 interpreting the C<@> sign. Defaults to C<@mailto@>.
583 Users in this group are exempt from password and PATH requirements.
584 This is not set by default.
588 This option controls when a password will be required when a user runs
589 B<sudo> with the B<-v> flag. It has the following possible values:
595 All the user's I<sudoers> entries for the current host must have
596 the C<NOPASSWD> flag set to avoid entering a password.
600 At least one of the user's I<sudoers> entries for the current host
601 must have the C<NOPASSWD> flag set to avoid entering a password.
605 The user need never enter a password to use the B<-v> flag.
609 The user must always enter a password to use the B<-v> flag.
613 The default value is `all'.
617 This option controls when a password will be required when a
618 user runs B<sudo> with the B<-l>. It has the following possible values:
624 All the user's I<sudoers> entries for the current host must have
625 the C<NOPASSWD> flag set to avoid entering a password.
629 At least one of the user's I<sudoers> entries for the current host
630 must have the C<NOPASSWD> flag set to avoid entering a password.
634 The user need never enter a password to use the B<-l> flag.
638 The user must always enter a password to use the B<-l> flag.
642 The default value is `any'.
646 B<Lists that can be used in a boolean context>:
652 Environment variables to be removed from the user's environment if
653 the variable's value contains C<%> or C</> characters. This can
654 be used to guard against printf-style format vulnerabilties in
655 poorly-written programs. The argument may be a double-quoted,
656 space-separated list or a single value without double-quotes. The
657 list can be replaced, added to, deleted from, or disabled by using
658 the C<=>, C<+=>, C<-=>, and C<!> operators respectively. The default
659 list of environment variable to check is printed when B<sudo> is
660 run by root with the I<-V> option.
664 Environment variables to be removed from the user's environment.
665 The argument may be a double-quoted, space-separated list or a
666 single value without double-quotes. The list can be replaced, added
667 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
668 C<!> operators respectively. The default list of environment
669 variable to remove is printed when B<sudo> is run by root with the
674 Environment variables to be preserved in the user's environment
675 when the I<env_reset> option is in effect. This allows fine-grained
676 control over the environment B<sudo>-spawned processes will receive.
677 The argument may be a double-quoted, space-separated list or a
678 single value without double-quotes. The list can be replaced, added
679 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
680 C<!> operators respectively. This list has no default members.
684 When logging via syslog(3), B<sudo> accepts the following values for the syslog
685 facility (the value of the B<syslog> Parameter): B<authpriv> (if your OS
686 supports it), B<auth>, B<daemon>, B<user>, B<local0>, B<local1>, B<local2>,
687 B<local3>, B<local4>, B<local5>, B<local6>, and B<local7>. The following
688 syslog priorities are supported: B<alert>, B<crit>, B<debug>, B<emerg>,
689 B<err>, B<info>, B<notice>, and B<warning>.
691 =head2 User Specification
693 User_Spec ::= User_list Host_List '=' Cmnd_Spec_List \
696 Cmnd_Spec_List ::= Cmnd_Spec |
697 Cmnd_Spec ',' Cmnd_Spec_List
699 Cmnd_Spec ::= Runas_Spec? ('NOPASSWD:' | 'PASSWD:')? Cmnd
701 Runas_Spec ::= '(' Runas_List ')'
703 A B<user specification> determines which commands a user may run
704 (and as what user) on specified hosts. By default, commands are
705 run as B<root>, but this can be changed on a per-command basis.
707 Let's break that down into its constituent parts:
711 A C<Runas_Spec> is simply a C<Runas_List> (as defined above)
712 enclosed in a set of parentheses. If you do not specify a
713 C<Runas_Spec> in the user specification, a default C<Runas_Spec>
714 of B<root> will be used. A C<Runas_Spec> sets the default for
715 commands that follow it. What this means is that for the entry:
717 dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/who
719 The user B<dgb> may run F</bin/ls>, F</bin/kill>, and
720 F</usr/bin/lprm> -- but only as B<operator>. E.g.,
722 sudo -u operator /bin/ls.
724 It is also possible to override a C<Runas_Spec> later on in an
725 entry. If we modify the entry like so:
727 dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
729 Then user B<dgb> is now allowed to run F</bin/ls> as B<operator>,
730 but F</bin/kill> and F</usr/bin/lprm> as B<root>.
732 =head2 NOPASSWD and PASSWD
734 By default, B<sudo> requires that a user authenticate him or herself
735 before running a command. This behavior can be modified via the
736 C<NOPASSWD> tag. Like a C<Runas_Spec>, the C<NOPASSWD> tag sets
737 a default for the commands that follow it in the C<Cmnd_Spec_List>.
738 Conversely, the C<PASSWD> tag can be used to reverse things.
741 ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
743 would allow the user B<ray> to run F</bin/kill>, F</bin/ls>, and
744 F</usr/bin/lprm> as root on the machine rushmore as B<root> without
745 authenticating himself. If we only want B<ray> to be able to
746 run F</bin/kill> without a password the entry would be:
748 ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
750 Note, however, that the C<PASSWD> tag has no effect on users who are
751 in the group specified by the exempt_group option.
753 By default, if the C<NOPASSWD> tag is applied to any of the entries
754 for a user on the current host, he or she will be able to run
755 C<sudo -l> without a password. Additionally, a user may only run
756 C<sudo -v> without a password if the C<NOPASSWD> tag is present
757 for all a user's entries that pertain to the current host.
758 This behavior may be overridden via the verifypw and listpw options.
760 =head2 Wildcards (aka meta characters):
762 B<sudo> allows shell-style I<wildcards> to be used in pathnames
763 as well as command line arguments in the I<sudoers> file. Wildcard
764 matching is done via the B<POSIX> C<fnmatch(3)> routine. Note that
765 these are I<not> regular expressions.
771 Matches any set of zero or more characters.
775 Matches any single character.
779 Matches any character in the specified range.
783 Matches any character B<not> in the specified range.
787 For any character "x", evaluates to "x". This is used to
788 escape special characters such as: "*", "?", "[", and "}".
792 Note that a forward slash ('/') will B<not> be matched by
793 wildcards used in the pathname. When matching the command
794 line arguments, however, as slash B<does> get matched by
795 wildcards. This is to make a path like:
799 match C</usr/bin/who> but not C</usr/bin/X11/xterm>.
801 =head2 Exceptions to wildcard rules:
803 The following exceptions apply to the above rules:
809 If the empty string C<""> is the only command line argument in the
810 I<sudoers> entry it means that command is not allowed to be run
811 with B<any> arguments.
815 =head2 Other special characters and reserved words:
817 The pound sign ('#') is used to indicate a comment (unless it
818 occurs in the context of a user name and is followed by one or
819 more digits, in which case it is treated as a uid). Both the
820 comment character and any text after it, up to the end of the line,
823 The reserved word B<ALL> is a built in I<alias> that always causes
824 a match to succeed. It can be used wherever one might otherwise
825 use a C<Cmnd_Alias>, C<User_Alias>, C<Runas_Alias>, or C<Host_Alias>.
826 You should not try to define your own I<alias> called B<ALL> as the
827 built in alias will be used in preference to your own. Please note
828 that using B<ALL> can be dangerous since in a command context, it
829 allows the user to run B<any> command on the system.
831 An exclamation point ('!') can be used as a logical I<not> operator
832 both in an I<alias> and in front of a C<Cmnd>. This allows one to
833 exclude certain values. Note, however, that using a C<!> in
834 conjunction with the built in C<ALL> alias to allow a user to
835 run "all but a few" commands rarely works as intended (see SECURITY
838 Long lines can be continued with a backslash ('\') as the last
839 character on the line.
841 Whitespace between elements in a list as well as special syntactic
842 characters in a I<User Specification> ('=', ':', '(', ')') is optional.
844 The following characters must be escaped with a backslash ('\') when
845 used as part of a word (e.g. a username or hostname):
846 '@', '!', '=', ':', ',', '(', ')', '\'.
850 Below are example I<sudoers> entries. Admittedly, some of
851 these are a bit contrived. First, we define our I<aliases>:
853 # User alias specification
854 User_Alias FULLTIMERS = millert, mikef, dowdy
855 User_Alias PARTTIMERS = bostley, jwfox, crawl
856 User_Alias WEBMASTERS = will, wendy, wim
858 # Runas alias specification
859 Runas_Alias OP = root, operator
860 Runas_Alias DB = oracle, sybase
862 # Host alias specification
863 Host_Alias SPARC = bigtime, eclipse, moet, anchor :\
864 SGI = grolsch, dandelion, black :\
865 ALPHA = widget, thalamus, foobar :\
866 HPPA = boa, nag, python
867 Host_Alias CUNETS = 128.138.0.0/255.255.0.0
868 Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
869 Host_Alias SERVERS = master, mail, www, ns
870 Host_Alias CDROM = orion, perseus, hercules
872 # Cmnd alias specification
873 Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
874 /usr/sbin/restore, /usr/sbin/rrestore
875 Cmnd_Alias KILL = /usr/bin/kill
876 Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm
877 Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown
878 Cmnd_Alias HALT = /usr/sbin/halt, /usr/sbin/fasthalt
879 Cmnd_Alias REBOOT = /usr/sbin/reboot, /usr/sbin/fastboot
880 Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
881 /usr/local/bin/tcsh, /usr/bin/rsh, \
883 Cmnd_Alias SU = /usr/bin/su
885 Here we override some of the compiled in default values. We want
886 B<sudo> to log via syslog(3) using the I<auth> facility in all cases.
887 We don't want to subject the full time staff to the B<sudo> lecture,
888 and user B<millert> need not give a password. In addition, on the
889 machines in the I<SERVERS> C<Host_Alias>, we keep an additional
890 local log file and make sure we log the year in each log line since
891 the log entries will be kept around for several years.
893 # Override built in defaults
895 Defaults:FULLTIMERS !lecture
896 Defaults:millert !authenticate
897 Defaults@SERVERS log_year, logfile=/var/log/sudo.log
899 The I<User specification> is the part that actually determines who may
903 %wheel ALL = (ALL) ALL
905 We let B<root> and any user in group B<wheel> run any command on any
908 FULLTIMERS ALL = NOPASSWD: ALL
910 Full time sysadmins (B<millert>, B<mikef>, and B<dowdy>) may run any
911 command on any host without authenticating themselves.
915 Part time sysadmins (B<bostley>, B<jwfox>, and B<crawl>) may run any
916 command on any host but they must authenticate themselves first
917 (since the entry lacks the C<NOPASSWD> tag).
921 The user B<jack> may run any command on the machines in the I<CSNETS> alias
922 (the networks C<128.138.243.0>, C<128.138.204.0>, and C<128.138.242.0>).
923 Of those networks, only C<128.138.204.0> has an explicit netmask (in
924 CIDR notation) indicating it is a class C network. For the other
925 networks in I<CSNETS>, the local machine's netmask will be used
930 The user B<lisa> may run any command on any host in the I<CUNETS> alias
931 (the class B network C<128.138.0.0>).
933 operator ALL = DUMPS, KILL, PRINTING, SHUTDOWN, HALT, REBOOT,\
936 The B<operator> user may run commands limited to simple maintenance.
937 Here, those are commands related to backups, killing processes, the
938 printing system, shutting down the system, and any commands in the
939 directory F</usr/oper/bin/>.
941 joe ALL = /usr/bin/su operator
943 The user B<joe> may only su(1) to operator.
945 pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root
947 The user B<pete> is allowed to change anyone's password except for
948 root on the I<HPPA> machines. Note that this assumes passwd(1)
949 does not take multiple usernames on the command line.
951 bob SPARC = (OP) ALL : SGI = (OP) ALL
953 The user B<bob> may run anything on the I<SPARC> and I<SGI> machines
954 as any user listed in the I<OP> C<Runas_Alias> (B<root> and B<operator>).
958 The user B<jim> may run any command on machines in the I<biglab> netgroup.
959 B<Sudo> knows that "biglab" is a netgroup due to the '+' prefix.
961 +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
963 Users in the B<secretaries> netgroup need to help manage the printers
964 as well as add and remove users, so they are allowed to run those
965 commands on all machines.
967 fred ALL = (DB) NOPASSWD: ALL
969 The user B<fred> can run commands as any user in the I<DB> C<Runas_Alias>
970 (B<oracle> or B<sybase>) without giving a password.
972 john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
974 On the I<ALPHA> machines, user B<john> may su to anyone except root
975 but he is not allowed to give su(1) any flags.
977 jen ALL, !SERVERS = ALL
979 The user B<jen> may run any command on any machine except for those
980 in the I<SERVERS> C<Host_Alias> (master, mail, www and ns).
982 jill SERVERS = /usr/bin/, !SU, !SHELLS
984 For any machine in the I<SERVERS> C<Host_Alias>, B<jill> may run
985 any commands in the directory /usr/bin/ except for those commands
986 belonging to the I<SU> and I<SHELLS> C<Cmnd_Aliases>.
988 steve CSNETS = (operator) /usr/local/op_commands/
990 The user B<steve> may run any command in the directory /usr/local/op_commands/
991 but only as user operator.
995 On his personal workstation, valkyrie, B<matt> needs to be able to
998 WEBMASTERS www = (www) ALL, (root) /usr/bin/su www
1000 On the host www, any user in the I<WEBMASTERS> C<User_Alias> (will,
1001 wendy, and wim), may run any command as user www (which owns the
1002 web pages) or simply su(1) to www.
1004 ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\
1005 /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
1007 Any user may mount or unmount a CD-ROM on the machines in the CDROM
1008 C<Host_Alias> (orion, perseus, hercules) without entering a password.
1009 This is a bit tedious for users to type, so it is a prime candidate
1010 for encapsulating in a shell script.
1012 =head1 SECURITY NOTES
1014 It is generally not effective to "subtract" commands from C<ALL>
1015 using the '!' operator. A user can trivially circumvent this
1016 by copying the desired command to a different name and then
1017 executing that. For example:
1019 bill ALL = ALL, !SU, !SHELLS
1021 Doesn't really prevent B<bill> from running the commands listed in
1022 I<SU> or I<SHELLS> since he can simply copy those commands to a
1023 different name, or use a shell escape from an editor or other
1024 program. Therefore, these kind of restrictions should be considered
1025 advisory at best (and reinforced by policy).
1029 The I<sudoers> file should B<always> be edited by the B<visudo>
1030 command which locks the file and does grammatical checking. It is
1031 imperative that I<sudoers> be free of syntax errors since B<sudo>
1032 will not run with a syntactically incorrect I<sudoers> file.
1034 When using netgroups of machines (as opposed to users), if you
1035 store fully qualified hostnames in the netgroup (as is usually the
1036 case), you either need to have the machine's hostname be fully qualified
1037 as returned by the C<hostname> command or use the I<fqdn> option in
1042 @sysconfdir@/sudoers List of who can run what
1043 /etc/group Local groups file
1044 /etc/netgroup List of network groups
1048 rsh(1), sudo(8), visudo(8), su(1), fnmatch(3).