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 C<DISPLAY>, C<XAUTHORITY>, C<XAUTHORIZATION>,
442 C<LANG>, C<LANGUAGE>, C<LC_*>,
443 and C<USER> (in addition to the C<SUDO_*> variables).
445 Of these, only C<TERM>, C<DISPLAY>, C<XAUTHORITY>, C<XAUTHORIZATION>,
446 C<LANG>, C<LANGUAGE>, and C<LC_*> are copied unaltered from the old environment.
447 The other variables are set to default values (possibly modified
448 by the value of the I<set_logname> option). If B<sudo> was compiled
449 with the C<SECURE_PATH> option, its value will be used for the C<PATH>
450 environment variable.
452 This option is enabled by default.
454 Other variables may be preserved with the I<env_keep> option.
458 If set, B<sudo> will apply the defaults specified for the target user's
459 login class if one exists. Only available if B<sudo> is configured with
460 the --with-logincap option. This flag is I<off> by default.
470 The number of tries a user gets to enter his/her password before
471 B<sudo> logs the failure and exits. The default is C<@passwd_tries@>.
475 B<Integers that can be used in a boolean context>:
481 Number of characters per line for the file log. This value is used
482 to decide when to wrap lines for nicer log files. This has no
483 effect on the syslog log file, only the file log. The default is
484 C<@loglen@> (use 0 or negate the option to disable word wrap).
486 =item timestamp_timeout
488 Number of minutes that can elapse before B<sudo> will ask for a
489 passwd again. The default is C<@timeout@>. Set this to C<0> to always
490 prompt for a password.
491 If set to a value less than C<0> the user's timestamp will never
492 expire. This can be used to allow users to create or delete their
493 own timestamps via C<sudo -v> and C<sudo -k> respectively.
497 Number of minutes before the B<sudo> password prompt times out.
498 The default is C<@password_timeout@>, set this to C<0> for no password timeout.
502 Umask to use when running the command. Negate this option or set
503 it to 0777 to preserve the user's umask. The default is C<@sudo_umask@>.
513 Subject of the mail sent to the I<mailto> user. The escape C<%h>
514 will expand to the hostname of the machine.
515 Default is C<@mailsub@>.
517 =item badpass_message
519 Message that is displayed if a user enters an incorrect password.
520 The default is C<@badpass_message@> unless insults are enabled.
524 The directory in which B<sudo> stores its timestamp files.
525 The default is F<@timedir@>.
529 The default prompt to use when asking for a password; can be overridden
530 via the B<-p> option or the C<SUDO_PROMPT> environment variable. Supports
531 two escapes: "%u" expands to the user's login name and "%h" expands
532 to the local hostname. The default value is C<@passprompt@>.
536 The default user to run commands as if the B<-u> flag is not specified
537 on the command line. This defaults to C<@runas_default@>.
541 Syslog priority to use when user authenticates successfully.
542 Defaults to C<@goodpri@>.
546 Syslog priority to use when user authenticates unsuccessfully.
547 Defaults to C<@badpri@>.
551 A colon (':') separated list of editors allowed to be used with
552 B<visudo>. B<visudo> will choose the editor that matches the user's
553 USER environment variable if possible, or the first editor in the
554 list that exists and is executable. The default is the path to vi
559 B<Strings that can be used in a boolean context>:
565 Path to the B<sudo> log file (not the syslog log file). Setting a path
566 turns on logging to a file; negating this option turns it off.
570 Syslog facility if syslog is being used for logging (negate to
571 disable syslog logging). Defaults to C<@logfac@>.
575 Path to mail program used to send warning mail.
576 Defaults to the path to sendmail found at configure time.
580 Flags to use when invoking mailer. Defaults to B<-t>.
584 Address to send warning and error mail to. The address should
585 be enclosed in double quotes (C<">) to protect against sudo
586 interpreting the C<@> sign. Defaults to C<@mailto@>.
590 Users in this group are exempt from password and PATH requirements. This
591 option is turned on for Debian.
595 This option controls when a password will be required when a user runs
596 B<sudo> with the B<-v> flag. It has the following possible values:
602 All the user's I<sudoers> entries for the current host must have
603 the C<NOPASSWD> flag set to avoid entering a password.
607 At least one of the user's I<sudoers> entries for the current host
608 must have the C<NOPASSWD> flag set to avoid entering a password.
612 The user need never enter a password to use the B<-v> flag.
616 The user must always enter a password to use the B<-v> flag.
620 The default value is `all'.
624 This option controls when a password will be required when a
625 user runs B<sudo> with the B<-l>. It has the following possible values:
631 All the user's I<sudoers> entries for the current host must have
632 the C<NOPASSWD> flag set to avoid entering a password.
636 At least one of the user's I<sudoers> entries for the current host
637 must have the C<NOPASSWD> flag set to avoid entering a password.
641 The user need never enter a password to use the B<-l> flag.
645 The user must always enter a password to use the B<-l> flag.
649 The default value is `any'.
653 B<Lists that can be used in a boolean context>:
659 Environment variables to be removed from the user's environment if
660 the variable's value contains C<%> or C</> characters. This can
661 be used to guard against printf-style format vulnerabilties in
662 poorly-written programs. The argument may be a double-quoted,
663 space-separated list or a single value without double-quotes. The
664 list can be replaced, added to, deleted from, or disabled by using
665 the C<=>, C<+=>, C<-=>, and C<!> operators respectively. The default
666 list of environment variable to check is printed when B<sudo> is
667 run by root with the I<-V> option.
671 Environment variables to be removed from the user's environment.
672 The argument may be a double-quoted, space-separated list or a
673 single value without double-quotes. The list can be replaced, added
674 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
675 C<!> operators respectively. The default list of environment
676 variable to remove is printed when B<sudo> is run by root with the
681 Environment variables to be preserved in the user's environment
682 when the I<env_reset> option is in effect. This allows fine-grained
683 control over the environment B<sudo>-spawned processes will receive.
684 The argument may be a double-quoted, space-separated list or a
685 single value without double-quotes. The list can be replaced, added
686 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
687 C<!> operators respectively. This list has no default members.
691 When logging via syslog(3), B<sudo> accepts the following values for the syslog
692 facility (the value of the B<syslog> Parameter): B<authpriv> (if your OS
693 supports it), B<auth>, B<daemon>, B<user>, B<local0>, B<local1>, B<local2>,
694 B<local3>, B<local4>, B<local5>, B<local6>, and B<local7>. The following
695 syslog priorities are supported: B<alert>, B<crit>, B<debug>, B<emerg>,
696 B<err>, B<info>, B<notice>, and B<warning>.
698 =head2 User Specification
700 User_Spec ::= User_list Host_List '=' Cmnd_Spec_List \
703 Cmnd_Spec_List ::= Cmnd_Spec |
704 Cmnd_Spec ',' Cmnd_Spec_List
706 Cmnd_Spec ::= Runas_Spec? ('NOPASSWD:' | 'PASSWD:')? Cmnd
708 Runas_Spec ::= '(' Runas_List ')'
710 A B<user specification> determines which commands a user may run
711 (and as what user) on specified hosts. By default, commands are
712 run as B<root>, but this can be changed on a per-command basis.
714 Let's break that down into its constituent parts:
718 A C<Runas_Spec> is simply a C<Runas_List> (as defined above)
719 enclosed in a set of parentheses. If you do not specify a
720 C<Runas_Spec> in the user specification, a default C<Runas_Spec>
721 of B<root> will be used. A C<Runas_Spec> sets the default for
722 commands that follow it. What this means is that for the entry:
724 dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/who
726 The user B<dgb> may run F</bin/ls>, F</bin/kill>, and
727 F</usr/bin/lprm> -- but only as B<operator>. E.g.,
729 sudo -u operator /bin/ls.
731 It is also possible to override a C<Runas_Spec> later on in an
732 entry. If we modify the entry like so:
734 dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
736 Then user B<dgb> is now allowed to run F</bin/ls> as B<operator>,
737 but F</bin/kill> and F</usr/bin/lprm> as B<root>.
739 =head2 NOPASSWD and PASSWD
741 By default, B<sudo> requires that a user authenticate him or herself
742 before running a command. This behavior can be modified via the
743 C<NOPASSWD> tag. Like a C<Runas_Spec>, the C<NOPASSWD> tag sets
744 a default for the commands that follow it in the C<Cmnd_Spec_List>.
745 Conversely, the C<PASSWD> tag can be used to reverse things.
748 ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
750 would allow the user B<ray> to run F</bin/kill>, F</bin/ls>, and
751 F</usr/bin/lprm> as root on the machine rushmore as B<root> without
752 authenticating himself. If we only want B<ray> to be able to
753 run F</bin/kill> without a password the entry would be:
755 ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
757 Note, however, that the C<PASSWD> tag has no effect on users who are
758 in the group specified by the exempt_group option.
760 By default, if the C<NOPASSWD> tag is applied to any of the entries
761 for a user on the current host, he or she will be able to run
762 C<sudo -l> without a password. Additionally, a user may only run
763 C<sudo -v> without a password if the C<NOPASSWD> tag is present
764 for all a user's entries that pertain to the current host.
765 This behavior may be overridden via the verifypw and listpw options.
767 =head2 Wildcards (aka meta characters):
769 B<sudo> allows shell-style I<wildcards> to be used in pathnames
770 as well as command line arguments in the I<sudoers> file. Wildcard
771 matching is done via the B<POSIX> C<fnmatch(3)> routine. Note that
772 these are I<not> regular expressions.
778 Matches any set of zero or more characters.
782 Matches any single character.
786 Matches any character in the specified range.
790 Matches any character B<not> in the specified range.
794 For any character "x", evaluates to "x". This is used to
795 escape special characters such as: "*", "?", "[", and "}".
799 Note that a forward slash ('/') will B<not> be matched by
800 wildcards used in the pathname. When matching the command
801 line arguments, however, as slash B<does> get matched by
802 wildcards. This is to make a path like:
806 match C</usr/bin/who> but not C</usr/bin/X11/xterm>.
808 =head2 Exceptions to wildcard rules:
810 The following exceptions apply to the above rules:
816 If the empty string C<""> is the only command line argument in the
817 I<sudoers> entry it means that command is not allowed to be run
818 with B<any> arguments.
822 =head2 Other special characters and reserved words:
824 The pound sign ('#') is used to indicate a comment (unless it
825 occurs in the context of a user name and is followed by one or
826 more digits, in which case it is treated as a uid). Both the
827 comment character and any text after it, up to the end of the line,
830 The reserved word B<ALL> is a built in I<alias> that always causes
831 a match to succeed. It can be used wherever one might otherwise
832 use a C<Cmnd_Alias>, C<User_Alias>, C<Runas_Alias>, or C<Host_Alias>.
833 You should not try to define your own I<alias> called B<ALL> as the
834 built in alias will be used in preference to your own. Please note
835 that using B<ALL> can be dangerous since in a command context, it
836 allows the user to run B<any> command on the system.
838 An exclamation point ('!') can be used as a logical I<not> operator
839 both in an I<alias> and in front of a C<Cmnd>. This allows one to
840 exclude certain values. Note, however, that using a C<!> in
841 conjunction with the built in C<ALL> alias to allow a user to
842 run "all but a few" commands rarely works as intended (see SECURITY
845 Long lines can be continued with a backslash ('\') as the last
846 character on the line.
848 Whitespace between elements in a list as well as special syntactic
849 characters in a I<User Specification> ('=', ':', '(', ')') is optional.
851 The following characters must be escaped with a backslash ('\') when
852 used as part of a word (e.g. a username or hostname):
853 '@', '!', '=', ':', ',', '(', ')', '\'.
857 Below are example I<sudoers> entries. Admittedly, some of
858 these are a bit contrived. First, we define our I<aliases>:
860 # User alias specification
861 User_Alias FULLTIMERS = millert, mikef, dowdy
862 User_Alias PARTTIMERS = bostley, jwfox, crawl
863 User_Alias WEBMASTERS = will, wendy, wim
865 # Runas alias specification
866 Runas_Alias OP = root, operator
867 Runas_Alias DB = oracle, sybase
869 # Host alias specification
870 Host_Alias SPARC = bigtime, eclipse, moet, anchor :\
871 SGI = grolsch, dandelion, black :\
872 ALPHA = widget, thalamus, foobar :\
873 HPPA = boa, nag, python
874 Host_Alias CUNETS = 128.138.0.0/255.255.0.0
875 Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
876 Host_Alias SERVERS = master, mail, www, ns
877 Host_Alias CDROM = orion, perseus, hercules
879 # Cmnd alias specification
880 Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
881 /usr/sbin/restore, /usr/sbin/rrestore
882 Cmnd_Alias KILL = /usr/bin/kill
883 Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm
884 Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown
885 Cmnd_Alias HALT = /usr/sbin/halt, /usr/sbin/fasthalt
886 Cmnd_Alias REBOOT = /usr/sbin/reboot, /usr/sbin/fastboot
887 Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
888 /usr/local/bin/tcsh, /usr/bin/rsh, \
890 Cmnd_Alias SU = /usr/bin/su
892 Here we override some of the compiled in default values. We want
893 B<sudo> to log via syslog(3) using the I<auth> facility in all cases.
894 We don't want to subject the full time staff to the B<sudo> lecture,
895 and user B<millert> need not give a password. In addition, on the
896 machines in the I<SERVERS> C<Host_Alias>, we keep an additional
897 local log file and make sure we log the year in each log line since
898 the log entries will be kept around for several years.
900 # Override built in defaults
902 Defaults:FULLTIMERS !lecture
903 Defaults:millert !authenticate
904 Defaults@SERVERS log_year, logfile=/var/log/sudo.log
906 The I<User specification> is the part that actually determines who may
910 %wheel ALL = (ALL) ALL
912 We let B<root> and any user in group B<wheel> run any command on any
915 FULLTIMERS ALL = NOPASSWD: ALL
917 Full time sysadmins (B<millert>, B<mikef>, and B<dowdy>) may run any
918 command on any host without authenticating themselves.
922 Part time sysadmins (B<bostley>, B<jwfox>, and B<crawl>) may run any
923 command on any host but they must authenticate themselves first
924 (since the entry lacks the C<NOPASSWD> tag).
928 The user B<jack> may run any command on the machines in the I<CSNETS> alias
929 (the networks C<128.138.243.0>, C<128.138.204.0>, and C<128.138.242.0>).
930 Of those networks, only C<128.138.204.0> has an explicit netmask (in
931 CIDR notation) indicating it is a class C network. For the other
932 networks in I<CSNETS>, the local machine's netmask will be used
937 The user B<lisa> may run any command on any host in the I<CUNETS> alias
938 (the class B network C<128.138.0.0>).
940 operator ALL = DUMPS, KILL, PRINTING, SHUTDOWN, HALT, REBOOT,\
943 The B<operator> user may run commands limited to simple maintenance.
944 Here, those are commands related to backups, killing processes, the
945 printing system, shutting down the system, and any commands in the
946 directory F</usr/oper/bin/>.
948 joe ALL = /usr/bin/su operator
950 The user B<joe> may only su(1) to operator.
952 pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root
954 The user B<pete> is allowed to change anyone's password except for
955 root on the I<HPPA> machines. Note that this assumes passwd(1)
956 does not take multiple usernames on the command line.
958 bob SPARC = (OP) ALL : SGI = (OP) ALL
960 The user B<bob> may run anything on the I<SPARC> and I<SGI> machines
961 as any user listed in the I<OP> C<Runas_Alias> (B<root> and B<operator>).
965 The user B<jim> may run any command on machines in the I<biglab> netgroup.
966 B<Sudo> knows that "biglab" is a netgroup due to the '+' prefix.
968 +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
970 Users in the B<secretaries> netgroup need to help manage the printers
971 as well as add and remove users, so they are allowed to run those
972 commands on all machines.
974 fred ALL = (DB) NOPASSWD: ALL
976 The user B<fred> can run commands as any user in the I<DB> C<Runas_Alias>
977 (B<oracle> or B<sybase>) without giving a password.
979 john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
981 On the I<ALPHA> machines, user B<john> may su to anyone except root
982 but he is not allowed to give su(1) any flags.
984 jen ALL, !SERVERS = ALL
986 The user B<jen> may run any command on any machine except for those
987 in the I<SERVERS> C<Host_Alias> (master, mail, www and ns).
989 jill SERVERS = /usr/bin/, !SU, !SHELLS
991 For any machine in the I<SERVERS> C<Host_Alias>, B<jill> may run
992 any commands in the directory /usr/bin/ except for those commands
993 belonging to the I<SU> and I<SHELLS> C<Cmnd_Aliases>.
995 steve CSNETS = (operator) /usr/local/op_commands/
997 The user B<steve> may run any command in the directory /usr/local/op_commands/
998 but only as user operator.
1000 matt valkyrie = KILL
1002 On his personal workstation, valkyrie, B<matt> needs to be able to
1003 kill hung processes.
1005 WEBMASTERS www = (www) ALL, (root) /usr/bin/su www
1007 On the host www, any user in the I<WEBMASTERS> C<User_Alias> (will,
1008 wendy, and wim), may run any command as user www (which owns the
1009 web pages) or simply su(1) to www.
1011 ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\
1012 /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
1014 Any user may mount or unmount a CD-ROM on the machines in the CDROM
1015 C<Host_Alias> (orion, perseus, hercules) without entering a password.
1016 This is a bit tedious for users to type, so it is a prime candidate
1017 for encapsulating in a shell script.
1019 =head1 SECURITY NOTES
1021 It is generally not effective to "subtract" commands from C<ALL>
1022 using the '!' operator. A user can trivially circumvent this
1023 by copying the desired command to a different name and then
1024 executing that. For example:
1026 bill ALL = ALL, !SU, !SHELLS
1028 Doesn't really prevent B<bill> from running the commands listed in
1029 I<SU> or I<SHELLS> since he can simply copy those commands to a
1030 different name, or use a shell escape from an editor or other
1031 program. Therefore, these kind of restrictions should be considered
1032 advisory at best (and reinforced by policy).
1036 The I<sudoers> file should B<always> be edited by the B<visudo>
1037 command which locks the file and does grammatical checking. It is
1038 imperative that I<sudoers> be free of syntax errors since B<sudo>
1039 will not run with a syntactically incorrect I<sudoers> file.
1041 When using netgroups of machines (as opposed to users), if you
1042 store fully qualified hostnames in the netgroup (as is usually the
1043 case), you either need to have the machine's hostname be fully qualified
1044 as returned by the C<hostname> command or use the I<fqdn> option in
1049 @sysconfdir@/sudoers List of who can run what
1050 /etc/group Local groups file
1051 /etc/netgroup List of network groups
1055 rsh(1), sudo(8), visudo(8), su(1), fnmatch(3).