2 Copyright (c) 1994-1996,1998-2004 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.96 2004/09/06 20:45:27 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 conflicting values, the last match is used (which
36 is 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. 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 with a network number, the netmask
156 of the host's ethernet interface(s) will be used when matching.
157 The netmask may be specified either in dotted quad notation (e.g.
158 255.255.255.0) or CIDR notation (number of bits, e.g. 24). A hostname
159 may include shell-style wildcards (see the L<Wildcards> section below),
160 but unless the C<hostname> command on your machine returns the fully
161 qualified hostname, you'll need to use the I<fqdn> option for wildcards
167 commandname ::= filename |
171 Cmnd ::= '!'* commandname |
176 A C<Cmnd_List> is a list of one or more commandnames, directories, and other
177 aliases. A commandname is a fully qualified filename which may include
178 shell-style wildcards (see the L<Wildcards> section below). A simple
179 filename allows the user to run the command with any arguments he/she
180 wishes. However, you may also specify command line arguments (including
181 wildcards). Alternately, you can specify C<""> to indicate that the command
182 may only be run B<without> command line arguments. A directory is a
183 fully qualified pathname ending in a '/'. When you specify a directory
184 in a C<Cmnd_List>, the user will be able to run any file within that directory
185 (but not in any subdirectories therein).
187 If a C<Cmnd> has associated command line arguments, then the arguments
188 in the C<Cmnd> must match exactly those given by the user on the command line
189 (or match the wildcards if there are any). Note that the following
190 characters must be escaped with a '\' if they are used in command
191 arguments: ',', ':', '=', '\'. The special command C<"sudoedit">
192 is used to permit a user to run B<sudo> with the B<-e> flag (or
193 as B<sudoedit>). It may take command line arguments just as
194 a normal command does.
198 Certain configuration options may be changed from their default
199 values at runtime via one or more C<Default_Entry> lines. These
200 may affect all users on any host, all users on a specific host, a
201 specific user, or commands being run as a specific user.
203 Default_Type ::= 'Defaults' |
204 'Defaults' '@' Host |
205 'Defaults' ':' User |
206 'Defaults' '>' RunasUser
208 Default_Entry ::= Default_Type Parameter_List
210 Parameter_List ::= Parameter |
211 Parameter ',' 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.
234 =item long_otp_prompt
236 When validating with a One Time Password scheme (B<S/Key> or B<OPIE>),
237 a two-line prompt is used to make it easier to cut and paste the
238 challenge to a local window. It's not as pretty as the default but
239 some people find it more convenient. This flag is I<@long_otp_prompt@>
244 If set, B<sudo> will ignore '.' or '' (current dir) in the C<PATH>
245 environment variable; the C<PATH> itself is not modified. This
246 flag is I<@ignore_dot@> by default. Currently, while it is possible
247 to set I<ignore_dot> in I<sudoers>, its value is not used. This option
248 should be considered read-only (it will be fixed in a future version
253 Send mail to the I<mailto> user every time a users runs B<sudo>.
254 This flag is I<off> by default.
258 Send mail to the I<mailto> user if the user running sudo does not
259 enter the correct password. This flag is I<off> by default.
263 If set, mail will be sent to the I<mailto> user if the invoking
264 user is not in the I<sudoers> file. This flag is I<@mail_no_user@>
269 If set, mail will be sent to the I<mailto> user if the invoking
270 user exists in the I<sudoers> file, but is not allowed to run
271 commands on the current host. This flag is I<@mail_no_host@> by default.
275 If set, mail will be sent to the I<mailto> user if the invoking
276 user is allowed to use B<sudo> but the command they are trying is not
277 listed in their I<sudoers> file entry or is explicitly denied.
278 This flag is I<@mail_no_perms@> by default.
282 If set, users must authenticate on a per-tty basis. Normally,
283 B<sudo> uses a directory in the ticket dir with the same name as
284 the user running it. With this flag enabled, B<sudo> will use a
285 file named for the tty the user is logged in on in that directory.
286 This flag is I<@tty_tickets@> by default.
290 If set, users must authenticate themselves via a password (or other
291 means of authentication) before they may run commands. This default
292 may be overridden via the C<PASSWD> and C<NOPASSWD> tags.
293 This flag is I<on> by default.
297 If set, root is allowed to run B<sudo> too. Disabling this prevents users
298 from "chaining" B<sudo> commands to get a root shell by doing something
299 like C<"sudo sudo /bin/sh">. Note, however, that turning off I<root_sudo>
300 will also prevent root and from running B<sudoedit>.
301 Disabling I<root_sudo> provides no real additional security; it
302 exists purely for historical reasons.
303 This flag is I<@root_sudo@> by default.
307 If set, the hostname will be logged in the (non-syslog) B<sudo> log file.
308 This flag is I<off> by default.
312 If set, the four-digit year will be logged in the (non-syslog) B<sudo> log file.
313 This flag is I<off> by default.
317 If set and B<sudo> is invoked with no arguments it acts as if the
318 B<-s> flag had been given. That is, it runs a shell as root (the
319 shell is determined by the C<SHELL> environment variable if it is
320 set, falling back on the shell listed in the invoking user's
321 /etc/passwd entry if not). This flag is I<off> by default.
325 If set and B<sudo> is invoked with the B<-s> flag the C<HOME>
326 environment variable will be set to the home directory of the target
327 user (which is root unless the B<-u> option is used). This effectively
328 makes the B<-s> flag imply B<-H>. This flag is I<off> by default.
330 =item always_set_home
332 If set, B<sudo> will set the C<HOME> environment variable to the home
333 directory of the target user (which is root unless the B<-u> option is used).
334 This effectively means that the B<-H> flag is always implied.
335 This flag is I<off> by default.
339 Normally, B<sudo> will tell the user when a command could not be
340 found in their C<PATH> environment variable. Some sites may wish
341 to disable this as it could be used to gather information on the
342 location of executables that the normal user does not have access
343 to. The disadvantage is that if the executable is simply not in
344 the user's C<PATH>, B<sudo> will tell the user that they are not
345 allowed to run it, which can be confusing. This flag is I<off> by
348 =item preserve_groups
350 By default B<sudo> will initialize the group vector to the list of
351 groups the target user is in. When I<preserve_groups> is set, the
352 user's existing group vector is left unaltered. The real and
353 effective group IDs, however, are still set to match the target
354 user. This flag is I<off> by default.
358 Set this flag if you want to put fully qualified hostnames in the
359 I<sudoers> file. I.e., instead of myhost you would use myhost.mydomain.edu.
360 You may still use the short form if you wish (and even mix the two).
361 Beware that turning on I<fqdn> requires B<sudo> to make DNS lookups
362 which may make B<sudo> unusable if DNS stops working (for example
363 if the machine is not plugged into the network). Also note that
364 you must use the host's official name as DNS knows it. That is,
365 you may not use a host alias (C<CNAME> entry) due to performance
366 issues and the fact that there is no way to get all aliases from
367 DNS. If your machine's hostname (as returned by the C<hostname>
368 command) is already fully qualified you shouldn't need to set
369 I<fqdn>. This flag is I<@fqdn@> by default.
373 If set, B<sudo> will insult users when they enter an incorrect
374 password. This flag is I<@insults@> by default.
378 If set, B<sudo> will only run when the user is logged in to a real
379 tty. This will disallow things like C<"rsh somehost sudo ls"> since
380 L<rsh(1)> does not allocate a tty. Because it is not possible to turn
381 off echo when there is no tty present, some sites may with to set
382 this flag to prevent a user from entering a visible password. This
383 flag is I<off> by default.
387 If set, B<visudo> will use the value of the EDITOR or VISUAL
388 environment variables before falling back on the default editor list.
389 Note that this may create a security hole as it allows the user to
390 run any arbitrary command as root without logging. A safer alternative
391 is to place a colon-separated list of editors in the C<editor>
392 variable. B<visudo> will then only use the EDITOR or VISUAL if
393 they match a value specified in C<editor>. This flag is C<@env_editor@> by
398 If set, B<sudo> will prompt for the root password instead of the password
399 of the invoking user. This flag is I<off> by default.
403 If set, B<sudo> will prompt for the password of the user defined by the
404 I<runas_default> option (defaults to C<@runas_default@>) instead of the
405 password of the invoking user. This flag is I<off> by default.
409 If set, B<sudo> will prompt for the password of the user specified by
410 the B<-u> flag (defaults to C<root>) instead of the password of the
411 invoking user. Note that this precludes the use of a uid not listed
412 in the passwd database as an argument to the B<-u> flag.
413 This flag is I<off> by default.
417 Normally, B<sudo> will set the C<LOGNAME> and C<USER> environment variables
418 to the name of the target user (usually root unless the B<-u> flag is given).
419 However, since some programs (including the RCS revision control system)
420 use C<LOGNAME> to determine the real identity of the user, it may be desirable
421 to change this behavior. This can be done by negating the set_logname option.
425 Normally, when B<sudo> executes a command the real and effective
426 UIDs are set to the target user (root by default). This option
427 changes that behavior such that the real UID is left as the invoking
428 user's UID. In other words, this makes B<sudo> act as a setuid
429 wrapper. This can be useful on systems that disable some potentially
430 dangerous functionality when a program is run setuid. Note, however,
431 that this means that sudo will run with the real uid of the invoking
432 user which may allow that user to kill B<sudo> before it can log a
433 failure, depending on how your OS defines the interaction between
434 signals and setuid processes.
438 If set, B<sudo> will reset the environment to only contain the
439 following variables: C<HOME>, C<LOGNAME>, C<PATH>, C<SHELL>, C<TERM>,
440 C<DISPLAY>, C<XAUTHORITY>, C<XAUTHORIZATION>,
441 C<LANG>, C<LANGUAGE>, C<LC_*>,
442 and C<USER> (in addition to the C<SUDO_*> variables).
444 Of these, only C<TERM>, C<DISPLAY>, C<XAUTHORITY>, C<XAUTHORIZATION>,
445 C<LANG>, C<LANGUAGE>, and C<LC_*> are copied unaltered from the old environment.
446 The other variables are set to default values (possibly modified
447 by the value of the I<set_logname> option). If B<sudo> was compiled
448 with the C<SECURE_PATH> option, its value will be used for the C<PATH>
449 environment variable.
451 This option is enabled by default.
453 Other variables may be preserved with the I<env_keep> option.
457 If set, B<sudo> will apply the defaults specified for the target user's
458 login class if one exists. Only available if B<sudo> is configured with
459 the --with-logincap option. This flag is I<off> by default.
463 If set, all commands run via sudo will behave as if the C<NOEXEC>
464 tag has been set, unless overridden by a C<EXEC> tag. See the
465 description of I<NOEXEC and EXEC> below as well as the L<PREVENTING SHELL
466 ESCAPES> section at the end of this manual. This flag is I<off> by default.
468 =item ignore_local_sudoers
470 If set via LDAP, parsing of @sysconfdir@/sudoers will be skipped.
471 This is intended for an Enterprises that wish to prevent the usage of local
472 sudoers files so that only LDAP is used. This thwarts the efforts of
473 rogue operators who would attempt to add roles to @sysconfdir@/sudoers.
474 When this option is present, @sysconfdir@/sudoers does not even need to exist.
475 Since this options tells sudo how to behave when no specific LDAP entries
476 have been matched, this sudoOption is only meaningful for the cn=defaults
477 section. This flag is I<off> by default.
487 The number of tries a user gets to enter his/her password before
488 B<sudo> logs the failure and exits. The default is C<@passwd_tries@>.
492 B<Integers that can be used in a boolean context>:
498 Number of characters per line for the file log. This value is used
499 to decide when to wrap lines for nicer log files. This has no
500 effect on the syslog log file, only the file log. The default is
501 C<@loglen@> (use 0 or negate the option to disable word wrap).
503 =item timestamp_timeout
505 Number of minutes that can elapse before B<sudo> will ask for a
506 passwd again. The default is C<@timeout@>. Set this to C<0> to always
507 prompt for a password.
508 If set to a value less than C<0> the user's timestamp will never
509 expire. This can be used to allow users to create or delete their
510 own timestamps via C<sudo -v> and C<sudo -k> respectively.
514 Number of minutes before the B<sudo> password prompt times out.
515 The default is C<@password_timeout@>, set this to C<0> for no password timeout.
519 Umask to use when running the command. Negate this option or set
520 it to 0777 to preserve the user's umask. The default is C<@sudo_umask@>.
530 Subject of the mail sent to the I<mailto> user. The escape C<%h>
531 will expand to the hostname of the machine.
532 Default is C<@mailsub@>.
534 =item badpass_message
536 Message that is displayed if a user enters an incorrect password.
537 The default is C<@badpass_message@> unless insults are enabled.
541 The directory in which B<sudo> stores its timestamp files.
542 The default is F<@timedir@>.
546 The owner of the timestamp directory and the timestamps stored therein.
547 The default is C<root>.
551 The default prompt to use when asking for a password; can be overridden
552 via the B<-p> option or the C<SUDO_PROMPT> environment variable.
553 The following percent (`C<%>') escapes are supported:
559 expanded to the invoking user's login name
563 expanded to the login name of the user the command will
564 be run as (defaults to root)
568 expanded to the local hostname without the domain name
572 expanded to the local hostname including the domain name
573 (on if the machine's hostname is fully qualified or the I<fqdn>
578 two consecutive C<%> characters are collaped into a single C<%> character
582 The default value is C<@passprompt@>.
586 The default user to run commands as if the B<-u> flag is not specified
587 on the command line. This defaults to C<@runas_default@>.
588 Note that if I<runas_default> is set it B<must> occur before
589 any C<Runas_Alias> specifications.
593 Syslog priority to use when user authenticates successfully.
594 Defaults to C<@goodpri@>.
598 Syslog priority to use when user authenticates unsuccessfully.
599 Defaults to C<@badpri@>.
603 A colon (':') separated list of editors allowed to be used with
604 B<visudo>. B<visudo> will choose the editor that matches the user's
605 USER environment variable if possible, or the first editor in the
606 list that exists and is executable. The default is the path to vi
611 Path to a shared library containing dummy versions of the execv(),
612 execve() and fexecve() library functions that just return an error.
613 This is used to implement the I<noexec> functionality on systems that
614 support C<LD_PRELOAD> or its equivalent. Defaults to F<@noexec_file@>.
618 B<Strings that can be used in a boolean context>:
624 This option controls when a short lecture will be printed along with
625 the password prompt. It has the following possible values:
631 Never lecture the user.
635 Only lecture the user the first time they run B<sudo>.
639 Always lecture the user.
643 If no value is specified, a value of I<once> is implied.
644 Negating the option results in a value of I<never> being used.
645 The default value is I<@lecture@>.
649 Path to a file containing an alternate sudo lecture that will
650 be used in place of the standard lecture if the named file exists.
654 Path to the B<sudo> log file (not the syslog log file). Setting a path
655 turns on logging to a file; negating this option turns it off.
659 Syslog facility if syslog is being used for logging (negate to
660 disable syslog logging). Defaults to C<@logfac@>.
664 Path to mail program used to send warning mail.
665 Defaults to the path to sendmail found at configure time.
669 Flags to use when invoking mailer. Defaults to B<-t>.
673 Address to send warning and error mail to. The address should
674 be enclosed in double quotes (C<">) to protect against sudo
675 interpreting the C<@> sign. Defaults to C<@mailto@>.
679 Users in this group are exempt from password and PATH requirements. This
680 option is turned on for Debian.
684 This option controls when a password will be required when a user runs
685 B<sudo> with the B<-v> flag. It has the following possible values:
691 All the user's I<sudoers> entries for the current host must have
692 the C<NOPASSWD> flag set to avoid entering a password.
696 At least one of the user's I<sudoers> entries for the current host
697 must have the C<NOPASSWD> flag set to avoid entering a password.
701 The user need never enter a password to use the B<-v> flag.
705 The user must always enter a password to use the B<-v> flag.
709 If no value is specified, a value of I<all> is implied.
710 Negating the option results in a value of I<never> being used.
711 The default value is I<all>.
715 This option controls when a password will be required when a
716 user runs B<sudo> with the B<-l> flag. It has the following possible values:
722 All the user's I<sudoers> entries for the current host must have
723 the C<NOPASSWD> flag set to avoid entering a password.
727 At least one of the user's I<sudoers> entries for the current host
728 must have the C<NOPASSWD> flag set to avoid entering a password.
732 The user need never enter a password to use the B<-l> flag.
736 The user must always enter a password to use the B<-l> flag.
740 If no value is specified, a value of I<any> is implied.
741 Negating the option results in a value of I<never> being used.
742 The default value is I<any>.
746 B<Lists that can be used in a boolean context>:
752 Environment variables to be removed from the user's environment if
753 the variable's value contains C<%> or C</> characters. This can
754 be used to guard against printf-style format vulnerabilities in
755 poorly-written programs. The argument may be a double-quoted,
756 space-separated list or a single value without double-quotes. The
757 list can be replaced, added to, deleted from, or disabled by using
758 the C<=>, C<+=>, C<-=>, and C<!> operators respectively. The default
759 list of environment variables to check is printed when B<sudo> is
760 run by root with the I<-V> option.
764 Environment variables to be removed from the user's environment.
765 The argument may be a double-quoted, space-separated list or a
766 single value without double-quotes. The list can be replaced, added
767 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
768 C<!> operators respectively. The default list of environment
769 variables to remove is printed when B<sudo> is run by root with the
770 I<-V> option. Note that many operating systems will remove potentially
771 dangerous variables from the environment of any setuid process (such
776 Environment variables to be preserved in the user's environment
777 when the I<env_reset> option is in effect. This allows fine-grained
778 control over the environment B<sudo>-spawned processes will receive.
779 The argument may be a double-quoted, space-separated list or a
780 single value without double-quotes. The list can be replaced, added
781 to, deleted from, or disabled by using the C<=>, C<+=>, C<-=>, and
782 C<!> operators respectively. This list has no default members.
786 When logging via L<syslog(3)>, B<sudo> accepts the following values
787 for the syslog facility (the value of the B<syslog> Parameter):
788 B<authpriv> (if your OS supports it), B<auth>, B<daemon>, B<user>,
789 B<local0>, B<local1>, B<local2>, B<local3>, B<local4>, B<local5>,
790 B<local6>, and B<local7>. The following syslog priorities are
791 supported: B<alert>, B<crit>, B<debug>, B<emerg>, B<err>, B<info>,
792 B<notice>, and B<warning>.
794 =head2 User Specification
796 User_Spec ::= User_List Host_List '=' Cmnd_Spec_List \
797 (':' Host_List '=' Cmnd_Spec_List)*
799 Cmnd_Spec_List ::= Cmnd_Spec |
800 Cmnd_Spec ',' Cmnd_Spec_List
802 Cmnd_Spec ::= Runas_Spec? Tag_Spec* Cmnd
804 Runas_Spec ::= '(' Runas_List ')'
806 Tag_Spec ::= ('NOPASSWD:' | 'PASSWD:' | 'NOEXEC:' | 'EXEC:')
808 A B<user specification> determines which commands a user may run
809 (and as what user) on specified hosts. By default, commands are
810 run as B<root>, but this can be changed on a per-command basis.
812 Let's break that down into its constituent parts:
816 A C<Runas_Spec> is simply a C<Runas_List> (as defined above)
817 enclosed in a set of parentheses. If you do not specify a
818 C<Runas_Spec> in the user specification, a default C<Runas_Spec>
819 of B<root> will be used. A C<Runas_Spec> sets the default for
820 commands that follow it. What this means is that for the entry:
822 dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/lprm
824 The user B<dgb> may run F</bin/ls>, F</bin/kill>, and
825 F</usr/bin/lprm> -- but only as B<operator>. E.g.,
827 $ sudo -u operator /bin/ls.
829 It is also possible to override a C<Runas_Spec> later on in an
830 entry. If we modify the entry like so:
832 dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
834 Then user B<dgb> is now allowed to run F</bin/ls> as B<operator>,
835 but F</bin/kill> and F</usr/bin/lprm> as B<root>.
839 A command may have zero or more tags associated with it. There are
840 four possible tag values, C<NOPASSWD>, C<PASSWD>, C<NOEXEC>, C<EXEC>.
841 Once a tag is set on a C<Cmnd>, subsequent C<Cmnd>s in the
842 C<Cmnd_Spec_List>, inherit the tag unless it is overridden by the
843 opposite tag (ie: C<PASSWD> overrides C<NOPASSWD> and C<EXEC>
844 overrides C<NOEXEC>).
846 =head3 NOPASSWD and PASSWD
848 By default, B<sudo> requires that a user authenticate him or herself
849 before running a command. This behavior can be modified via the
850 C<NOPASSWD> tag. Like a C<Runas_Spec>, the C<NOPASSWD> tag sets
851 a default for the commands that follow it in the C<Cmnd_Spec_List>.
852 Conversely, the C<PASSWD> tag can be used to reverse things.
855 ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
857 would allow the user B<ray> to run F</bin/kill>, F</bin/ls>, and
858 F</usr/bin/lprm> as root on the machine rushmore as B<root> without
859 authenticating himself. If we only want B<ray> to be able to
860 run F</bin/kill> without a password the entry would be:
862 ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
864 Note, however, that the C<PASSWD> tag has no effect on users who are
865 in the group specified by the exempt_group option.
867 By default, if the C<NOPASSWD> tag is applied to any of the entries
868 for a user on the current host, he or she will be able to run
869 C<sudo -l> without a password. Additionally, a user may only run
870 C<sudo -v> without a password if the C<NOPASSWD> tag is present
871 for all a user's entries that pertain to the current host.
872 This behavior may be overridden via the verifypw and listpw options.
874 =head3 NOEXEC and EXEC
876 If sudo has been compiled with I<noexec> support and the underlying
877 operating system support it, the C<NOEXEC> tag can be used to prevent
878 a dynamically-linked executable from running further commands itself.
880 In the following example, user B<aaron> may run F</usr/bin/more>
881 and F</usr/bin/vi> but shell escapes will be disabled.
883 aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
885 See the L<PREVENTING SHELL ESCAPES> section below for more details
886 on how I<noexec> works and whether or not it will work on your system.
890 B<sudo> allows shell-style I<wildcards> (aka meta or glob characters)
891 to be used in pathnames as well as command line arguments in the
892 I<sudoers> file. Wildcard matching is done via the B<POSIX>
893 L<fnmatch(3)> routine. Note that these are I<not> regular expressions.
899 Matches any set of zero or more characters.
903 Matches any single character.
907 Matches any character in the specified range.
911 Matches any character B<not> in the specified range.
915 For any character "x", evaluates to "x". This is used to
916 escape special characters such as: "*", "?", "[", and "}".
920 Note that a forward slash ('/') will B<not> be matched by
921 wildcards used in the pathname. When matching the command
922 line arguments, however, a slash B<does> get matched by
923 wildcards. This is to make a path like:
927 match F</usr/bin/who> but not F</usr/bin/X11/xterm>.
929 WARNING: a pathname with wildcards will B<not> match a user command
930 that consists of a relative path. In other words, given the
931 following I<sudoers> entry:
933 billy workstation = /usr/bin/*
935 user billy will be able to run any command in /usr/bin as root, such
936 as F</usr/bin/w>. The following two command will be allowed (the first
937 assumes that F</usr/bin> is in the user's path):
942 However, this will not:
947 For this reason you should only B<grant> access to commands using
948 wildcards and never B<restrict> access using them. This limitation
949 will be removed in a future version of B<sudo>.
951 =head2 Exceptions to wildcard rules
953 The following exceptions apply to the above rules:
959 If the empty string C<""> is the only command line argument in the
960 I<sudoers> entry it means that command is not allowed to be run
961 with B<any> arguments.
965 =head2 Other special characters and reserved words
967 The pound sign ('#') is used to indicate a comment (unless it
968 occurs in the context of a user name and is followed by one or
969 more digits, in which case it is treated as a uid). Both the
970 comment character and any text after it, up to the end of the line,
973 The reserved word B<ALL> is a built-in I<alias> that always causes
974 a match to succeed. It can be used wherever one might otherwise
975 use a C<Cmnd_Alias>, C<User_Alias>, C<Runas_Alias>, or C<Host_Alias>.
976 You should not try to define your own I<alias> called B<ALL> as the
977 built-in alias will be used in preference to your own. Please note
978 that using B<ALL> can be dangerous since in a command context, it
979 allows the user to run B<any> command on the system.
981 An exclamation point ('!') can be used as a logical I<not> operator
982 both in an I<alias> and in front of a C<Cmnd>. This allows one to
983 exclude certain values. Note, however, that using a C<!> in
984 conjunction with the built-in C<ALL> alias to allow a user to
985 run "all but a few" commands rarely works as intended (see SECURITY
988 Long lines can be continued with a backslash ('\') as the last
989 character on the line.
991 Whitespace between elements in a list as well as special syntactic
992 characters in a I<User Specification> ('=', ':', '(', ')') is optional.
994 The following characters must be escaped with a backslash ('\') when
995 used as part of a word (e.g. a username or hostname):
996 '@', '!', '=', ':', ',', '(', ')', '\'.
1000 @sysconfdir@/sudoers List of who can run what
1001 /etc/group Local groups file
1002 /etc/netgroup List of network groups
1006 Since the I<sudoers> file is parsed in a single pass, order is
1007 important. In general, you should structure I<sudoers> such that
1008 the C<Host_Alias>, C<User_Alias>, and C<Cmnd_Alias> specifications
1009 come first, followed by any C<Default_Entry> lines, and finally the
1010 C<Runas_Alias> and user specifications. The basic rule of thumb
1011 is you cannot reference an Alias that has not already been defined.
1013 Below are example I<sudoers> entries. Admittedly, some of
1014 these are a bit contrived. First, we define our I<aliases>:
1016 # User alias specification
1017 User_Alias FULLTIMERS = millert, mikef, dowdy
1018 User_Alias PARTTIMERS = bostley, jwfox, crawl
1019 User_Alias WEBMASTERS = will, wendy, wim
1021 # Runas alias specification
1022 Runas_Alias OP = root, operator
1023 Runas_Alias DB = oracle, sybase
1025 # Host alias specification
1026 Host_Alias SPARC = bigtime, eclipse, moet, anchor :\
1027 SGI = grolsch, dandelion, black :\
1028 ALPHA = widget, thalamus, foobar :\
1029 HPPA = boa, nag, python
1030 Host_Alias CUNETS = 128.138.0.0/255.255.0.0
1031 Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
1032 Host_Alias SERVERS = master, mail, www, ns
1033 Host_Alias CDROM = orion, perseus, hercules
1035 # Cmnd alias specification
1036 Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
1037 /usr/sbin/restore, /usr/sbin/rrestore
1038 Cmnd_Alias KILL = /usr/bin/kill
1039 Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm
1040 Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown
1041 Cmnd_Alias HALT = /usr/sbin/halt
1042 Cmnd_Alias REBOOT = /usr/sbin/reboot
1043 Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
1044 /usr/local/bin/tcsh, /usr/bin/rsh, \
1046 Cmnd_Alias SU = /usr/bin/su
1048 Here we override some of the compiled in default values. We want
1049 B<sudo> to log via L<syslog(3)> using the I<auth> facility in all
1050 cases. We don't want to subject the full time staff to the B<sudo>
1051 lecture, user B<millert> need not give a password, and we don't
1052 want to reset the C<LOGNAME> or C<USER> environment variables when
1053 running commands as root. Additionally, on the machines in the
1054 I<SERVERS> C<Host_Alias>, we keep an additional local log file and
1055 make sure we log the year in each log line since the log entries
1056 will be kept around for several years.
1058 # Override built-in defaults
1059 Defaults syslog=auth
1060 Defaults>root !set_logname
1061 Defaults:FULLTIMERS !lecture
1062 Defaults:millert !authenticate
1063 Defaults@SERVERS log_year, logfile=/var/log/sudo.log
1065 The I<User specification> is the part that actually determines who may
1068 root ALL = (ALL) ALL
1069 %wheel ALL = (ALL) ALL
1071 We let B<root> and any user in group B<wheel> run any command on any
1074 FULLTIMERS ALL = NOPASSWD: ALL
1076 Full time sysadmins (B<millert>, B<mikef>, and B<dowdy>) may run any
1077 command on any host without authenticating themselves.
1079 PARTTIMERS ALL = ALL
1081 Part time sysadmins (B<bostley>, B<jwfox>, and B<crawl>) may run any
1082 command on any host but they must authenticate themselves first
1083 (since the entry lacks the C<NOPASSWD> tag).
1087 The user B<jack> may run any command on the machines in the I<CSNETS> alias
1088 (the networks C<128.138.243.0>, C<128.138.204.0>, and C<128.138.242.0>).
1089 Of those networks, only C<128.138.204.0> has an explicit netmask (in
1090 CIDR notation) indicating it is a class C network. For the other
1091 networks in I<CSNETS>, the local machine's netmask will be used
1096 The user B<lisa> may run any command on any host in the I<CUNETS> alias
1097 (the class B network C<128.138.0.0>).
1099 operator ALL = DUMPS, KILL, SHUTDOWN, HALT, REBOOT, PRINTING,\
1100 sudoedit /etc/printcap, /usr/oper/bin/
1102 The B<operator> user may run commands limited to simple maintenance.
1103 Here, those are commands related to backups, killing processes, the
1104 printing system, shutting down the system, and any commands in the
1105 directory F</usr/oper/bin/>.
1107 joe ALL = /usr/bin/su operator
1109 The user B<joe> may only L<su(1)> to operator.
1111 pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root
1113 The user B<pete> is allowed to change anyone's password except for
1114 root on the I<HPPA> machines. Note that this assumes L<passwd(1)>
1115 does not take multiple usernames on the command line.
1117 bob SPARC = (OP) ALL : SGI = (OP) ALL
1119 The user B<bob> may run anything on the I<SPARC> and I<SGI> machines
1120 as any user listed in the I<OP> C<Runas_Alias> (B<root> and B<operator>).
1124 The user B<jim> may run any command on machines in the I<biglab> netgroup.
1125 B<Sudo> knows that "biglab" is a netgroup due to the '+' prefix.
1127 +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
1129 Users in the B<secretaries> netgroup need to help manage the printers
1130 as well as add and remove users, so they are allowed to run those
1131 commands on all machines.
1133 fred ALL = (DB) NOPASSWD: ALL
1135 The user B<fred> can run commands as any user in the I<DB> C<Runas_Alias>
1136 (B<oracle> or B<sybase>) without giving a password.
1138 john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
1140 On the I<ALPHA> machines, user B<john> may su to anyone except root
1141 but he is not allowed to give L<su(1)> any flags.
1143 jen ALL, !SERVERS = ALL
1145 The user B<jen> may run any command on any machine except for those
1146 in the I<SERVERS> C<Host_Alias> (master, mail, www and ns).
1148 jill SERVERS = /usr/bin/, !SU, !SHELLS
1150 For any machine in the I<SERVERS> C<Host_Alias>, B<jill> may run
1151 any commands in the directory /usr/bin/ except for those commands
1152 belonging to the I<SU> and I<SHELLS> C<Cmnd_Aliases>.
1154 steve CSNETS = (operator) /usr/local/op_commands/
1156 The user B<steve> may run any command in the directory /usr/local/op_commands/
1157 but only as user operator.
1159 matt valkyrie = KILL
1161 On his personal workstation, valkyrie, B<matt> needs to be able to
1162 kill hung processes.
1164 WEBMASTERS www = (www) ALL, (root) /usr/bin/su www
1166 On the host www, any user in the I<WEBMASTERS> C<User_Alias> (will,
1167 wendy, and wim), may run any command as user www (which owns the
1168 web pages) or simply L<su(1)> to www.
1170 ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\
1171 /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
1173 Any user may mount or unmount a CD-ROM on the machines in the CDROM
1174 C<Host_Alias> (orion, perseus, hercules) without entering a password.
1175 This is a bit tedious for users to type, so it is a prime candidate
1176 for encapsulating in a shell script.
1178 =head1 SECURITY NOTES
1180 It is generally not effective to "subtract" commands from C<ALL>
1181 using the '!' operator. A user can trivially circumvent this
1182 by copying the desired command to a different name and then
1183 executing that. For example:
1185 bill ALL = ALL, !SU, !SHELLS
1187 Doesn't really prevent B<bill> from running the commands listed in
1188 I<SU> or I<SHELLS> since he can simply copy those commands to a
1189 different name, or use a shell escape from an editor or other
1190 program. Therefore, these kind of restrictions should be considered
1191 advisory at best (and reinforced by policy).
1193 =head1 PREVENTING SHELL ESCAPES
1195 Once B<sudo> executes a program, that program is free to do whatever
1196 it pleases, including run other programs. This can be a security
1197 issue since it is not uncommon for a program to allow shell escapes,
1198 which lets a user bypass B<sudo>'s restrictions. Common programs
1199 that permit shell escapes include shells (obviously), editors,
1200 paginators, mail and terminal programs.
1202 Many systems that support shared libraries have the ability to
1203 override default library functions by pointing an environment
1204 variable (usually C<LD_PRELOAD>) to an alternate shared library.
1205 On such systems, B<sudo>'s I<noexec> functionality can be used to
1206 prevent a program run by sudo from executing any other programs.
1207 Note, however, that this applies only to native dynamically-linked
1208 executables. Statically-linked executables and foreign executables
1209 running under binary emulation are not affected.
1211 To tell whether or not B<sudo> supports I<noexec>, you can run
1212 the following as root:
1214 sudo -V | grep "dummy exec"
1216 If the resulting output contains a line that begins with:
1218 File containing dummy exec functions:
1220 then B<sudo> may be able to replace the exec family of functions
1221 in the standard library with its own that simply return an error.
1222 Unfortunately, there is no foolproof way to know whether or not
1223 I<noexec> will work at compile-time. I<Noexec> should work on
1224 SunOS, Solaris, *BSD, Linux, IRIX, Tru64 UNIX, MacOS X, and HP-UX
1225 11.x. It is known B<not> to work on AIX and UnixWare. I<Noexec>
1226 is expected to work on most operating systems that support the
1227 C<LD_PRELOAD> environment variable. Check your operating system's
1228 manual pages for the dynamic linker (usually ld.so, ld.so.1, dyld,
1229 dld.sl, rld, or loader) to see if C<LD_PRELOAD> is supported.
1231 To enable I<noexec> for a command, use the C<NOEXEC> tag as documented
1232 in the User Specification section above. Here is that example again:
1234 aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
1236 This allows user B<aaron> to run F</usr/bin/more> and F</usr/bin/vi>
1237 with I<noexec> enabled. This will prevent those two commands from
1238 executing other commands (such as a shell). If you are unsure
1239 whether or not your system is capable of supporting I<noexec> you
1240 can always just try it out and see if it works.
1242 Note that disabling shell escapes is not a panacea. Programs running
1243 as root are still capable of many potentially hazardous operations
1244 (such as changing or overwriting files) that could lead to unintended
1245 privilege escalation. In the specific case of an editor, a safer
1246 approach is to give the user permission to run B<sudoedit>.
1250 L<rsh(1)>, L<su(1)>, L<fnmatch(3)>, L<sudo(@mansectsu@)>, L<visudo(@mansectsu@)>
1254 The I<sudoers> file should B<always> be edited by the B<visudo>
1255 command which locks the file and does grammatical checking. It is
1256 imperative that I<sudoers> be free of syntax errors since B<sudo>
1257 will not run with a syntactically incorrect I<sudoers> file.
1259 When using netgroups of machines (as opposed to users), if you
1260 store fully qualified hostnames in the netgroup (as is usually the
1261 case), you either need to have the machine's hostname be fully qualified
1262 as returned by the C<hostname> command or use the I<fqdn> option in
1267 If you feel you have found a bug in B<sudo>, please submit a bug report
1268 at http://www.sudo.ws/sudo/bugs/
1272 Commercial support is available for B<sudo>, see
1273 http://www.sudo.ws/sudo/support.html for details.
1275 Limited free support is available via the sudo-users mailing list,
1276 see http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or
1277 search the archives.
1281 B<Sudo> is provided ``AS IS'' and any express or implied warranties,
1282 including, but not limited to, the implied warranties of merchantability
1283 and fitness for a particular purpose are disclaimed. See the LICENSE
1284 file distributed with B<sudo> or http://www.sudo.ws/sudo/license.html
1285 for complete details.