NAME
sudoers – default sudo security policy pluginDESCRIPTION
The sudoers policy plugin determines a user’s sudo privileges. It is the default sudo policy plugin. The policy is driven by the /etc/sudoers file or, optionally in LDAP. The policy format is described in detail in the Sx SUDOERS FILE FORMAT section. For information on storing sudoers policy information in LDAP, please see sudoers.ldap5.Configuring sudo.conf for sudoers
sudo consults the sudo.conf5 file to determine which policy and and I/O logging plugins to load. If no sudo.conf5 file is present, or if it contains no Plugin lines, sudoers will be used for policy decisions and I/O logging. To explicitly configure sudo.conf5 to use the sudoers plugin, the following configuration can be used.Plugin sudoers_policy sudoers.so Plugin sudoers_io sudoers.so
Starting with sudo 1.8.5, it is possible to specify optional arguments to the sudoers plugin in the sudo.conf5 file. These arguments, if present, should be listed after the path to the plugin (i.e. after sudoers.so ) Multiple arguments may be specified, separated by white space. For example:
Plugin sudoers_policy sudoers.so sudoers_mode=0400
The following plugin arguments are supported:
- ldap_conf=pathname
- The ldap_conf argument can be used to override the default path to the ldap.conf file.
- ldap_secret=pathname
- The ldap_secret argument can be used to override the default path to the ldap.secret file.
- sudoers_file=pathname
- The sudoers_file argument can be used to override the default path to the sudoers file.
- sudoers_uid=uid
- The sudoers_uid argument can be used to override the default owner of the sudoers file. It should be specified as a numeric user ID.
- sudoers_gid=gid
- The sudoers_gid argument can be used to override the default group of the sudoers file. It must be specified as a numeric group ID (not a group name).
- sudoers_mode=mode
- The sudoers_mode argument can be used to override the default file mode for the sudoers file. It should be specified as an octal value.
For more information on configuring sudo.conf5, please refer to its manual.
Authentication and logging
The sudoers security policy requires that most users authenticate themselves before they can use sudo A password is not required if the invoking user is root, if the target user is the same as the invoking user, or if the policy has disabled authentication for the user or command. Unlike su(1), when sudoers requires authentication, it validates the invoking user’s credentials, not the target user’s (or root’s) credentials. This can be changed via the rootpw targetpw and runaspw flags, described later.If a user who is not listed in the policy tries to run a command via sudo mail is sent to the proper authorities. The address used for such mail is configurable via the mailto Defaults entry (described later) and defaults to root
Note that mail will not be sent if an unauthorized user tries to run sudo with the –l or –v option. This allows users to determine for themselves whether or not they are allowed to use sudo
If sudo is run by root and the SUDO_USER environment variable is set, the sudoers policy will use this value to determine who the actual user is. This can be used by a user to log commands through sudo even when a root shell has been invoked. It also allows the –e option to remain useful even when invoked via a sudo-run script or program. Note, however, that the sudoers lookup is still done for root, not the user specified by SUDO_USER
sudoers uses per-user time stamp files for credential caching. Once a user has been authenticated, a record is written containing the uid that was used to authenticate, the terminal session ID, and a time stamp (using a monotonic clock if one is available). The user may then use sudo without a password for a short period of time Po 15 minutes unless overridden by the timeout option Pc . By default, sudoers uses a separate record for each tty, which means that a user’s login sessions are authenticated separately. The tty_tickets option can be disabled to force the use of a single time stamp for all of a user’s sessions.
sudoers can log both successful and unsuccessful attempts (as well as errors) to syslog(3), a log file, or both. By default, sudoers will log via syslog(3) but this is changeable via the syslog and logfile Defaults settings.
sudoers also supports logging a command’s input and output streams. I/O logging is not on by default but can be enabled using the log_input and log_output Defaults flags as well as the LOG_INPUT and LOG_OUTPUT command tags.
Command environment
Since environment variables can influence program behavior, sudoers provides a means to restrict which variables from the user’s environment are inherited by the command to be run. There are two distinct ways sudoers can deal with environment variables.By default, the env_reset option is enabled. This causes commands to be executed with a new, minimal environment. On AIX (and Linux systems without PAM), the environment is initialized with the contents of the /etc/environment file. The new environment contains the TERM PATH HOME MAIL SHELL LOGNAME USER USERNAME and SUDO_* variables in addition to variables from the invoking process permitted by the env_check and env_keep options. This is effectively a whitelist for environment variables.
If, however, the env_reset option is disabled, any variables not explicitly denied by the env_check and env_delete options are inherited from the invoking process. In this case, env_check and env_delete behave like a blacklist. Since it is not possible to blacklist all potentially dangerous environment variables, use of the default env_reset behavior is encouraged.
In all cases, environment variables with a value beginning with () are removed as they could be interpreted as bash functions. The list of environment variables that sudo allows or denies is contained in the output of “sudo -V ” when run as root.
Note that the dynamic linker on most operating systems will remove variables that can control dynamic linking from the environment of setuid executables, including sudo Depending on the operating system this may include _RLD* DYLD_* LD_* LDR_* LIBPATH SHLIB_PATH and others. These type of variables are removed from the environment before sudo even begins execution and, as such, it is not possible for sudo to preserve them.
As a special case, if sudo ‘s –i option (initial login) is specified, sudoers will initialize the environment regardless of the value of env_reset The DISPLAY PATH and TERM variables remain unchanged; HOME MAIL SHELL USER and LOGNAME are set based on the target user. On AIX (and Linux systems without PAM), the contents of /etc/environment are also included. All other environment variables are removed.
Finally, if the env_file option is defined, any variables present in that file will be set to their specified values as long as they would not conflict with an existing environment variable.
SUDOERS FILE FORMAT
The sudoers file is composed of two types of entries: aliases (basically variables) and user specifications (which specify who may run what).When multiple entries match for a user, they are applied in order. Where there are multiple matches, the last match is used (which is not necessarily the most specific match).
The sudoers grammar will be described below in Extended Backus-Naur Form (EBNF). Don’t despair if you are unfamiliar with EBNF; it is fairly simple, and the definitions below are annotated.
Quick guide to EBNF
EBNF is a concise and exact way of describing the grammar of a language. Each EBNF definition is made up of production rules E.g.,symbol ::= definition | alternate1 | alternate2 …
Each production rule references others and thus makes up a grammar for the language. EBNF also contains the following operators, which many readers will recognize from regular expressions. Do not, however, confuse them with “wildcard” characters, which have different meanings.
- ?
- Means that the preceding symbol (or group of symbols) is optional. That is, it may appear once or not at all.
- *
- Means that the preceding symbol (or group of symbols) may appear zero or more times.
- +
- Means that the preceding symbol (or group of symbols) may appear one or more times.
Parentheses may be used to group symbols together. For clarity, we will use single quotes (”) to designate what is a verbatim character string (as opposed to a symbol name).
Aliases
There are four kinds of aliases: User_Alias Runas_Alias Host_Alias and Cmnd_Alias
Alias ::= ‘User_Alias’ User_Alias (‘:’ User_Alias)* |
‘Runas_Alias’ Runas_Alias (‘:’ Runas_Alias)* |
‘Host_Alias’ Host_Alias (‘:’ Host_Alias)* |
‘Cmnd_Alias’ Cmnd_Alias (‘:’ Cmnd_Alias)*
User_Alias ::= NAME ‘=’ User_List
Runas_Alias ::= NAME ‘=’ Runas_List
Host_Alias ::= NAME ‘=’ Host_List
Cmnd_Alias ::= NAME ‘=’ Cmnd_List
NAME ::= [A-Z]([A-Z][0-9]_)*
Each alias definition is of the form
Alias_Type NAME = item1, item2, …
where Alias_Type is one of User_Alias Runas_Alias Host_Alias or Cmnd_Alias A NAME is a string of uppercase letters, numbers, and underscore characters (`_’ ) A NAME must start with an uppercase letter. It is possible to put several alias definitions of the same type on a single line, joined by a colon (`:’ ) E.g.,
Alias_Type NAME = item1, item2, item3 : NAME = item4, item5
The definitions of what constitutes a valid alias member follow.
User_List ::= User |
User ‘,’ User_List
User ::= ‘!’* user name |
‘!’* #uid |
‘!’* %group |
‘!’* %#gid |
‘!’* +netgroup |
‘!’* %:nonunix_group |
‘!’* %:#nonunix_gid |
‘!’* User_Alias
A User_List is made up of one or more user names, user IDs (prefixed with `#’ ) , system group names and IDs (prefixed with `%’ and `%#’ respectively), netgroups (prefixed with `+’ ) , non-Unix group names and IDs (prefixed with `%:’ and `%:#’ respectively) and User_Alias es. Each list item may be prefixed with zero or more `!’ operators. An odd number of `!’ operators negate the value of the item; an even number just cancel each other out.
A user name uid group gid netgroup nonunix_group or nonunix_gid may be enclosed in double quotes to avoid the need for escaping special characters. Alternately, special characters may be specified in escaped hex mode, e.g. \x20 for space. When using double quotes, any prefix characters must be included inside the quotes.
The actual nonunix_group and nonunix_gid syntax depends on the underlying group provider plugin. For instance, the QAS AD plugin supports the following formats:
- Group in the same domain: "%:Group Name"
- Group in any domain: "%:Group [email protected]"
- Group SID: "%:S-1-2-34-5678901234-5678901234-5678901234-567"
See Sx GROUP PROVIDER PLUGINS for more information.
Note that quotes around group names are optional. Unquoted strings must use a backslash (`\’ ) to escape spaces and special characters. See Sx Other special characters and reserved words for a list of characters that need to be escaped.
Runas_List ::= Runas_Member |
Runas_Member ‘,’ Runas_List
Runas_Member ::= ‘!’* user name |
‘!’* #uid |
‘!’* %group |
‘!’* %#gid |
‘!’* %:nonunix_group |
‘!’* %:#nonunix_gid |
‘!’* +netgroup |
‘!’* Runas_Alias
A Runas_List is similar to a User_List except that instead of User_Alias es it can contain Runas_Alias es Note that user names and groups are matched as strings. In other words, two users (groups) with the same uid (gid) are considered to be distinct. If you wish to match all user names with the same uid (e.g. root and toor), you can use a uid instead (#0 in the example given).
Host_List ::= Host |
Host ‘,’ Host_List
Host ::= ‘!’* host name |
‘!’* ip_addr |
‘!’* network(/netmask)? |
‘!’* +netgroup |
‘!’* Host_Alias
A Host_List is made up of one or more host names, IP addresses, network numbers, netgroups (prefixed with `+’ ) and other aliases. Again, the value of an item may be negated with the `!’ operator. If you do not specify a netmask along with the network number, sudo will query each of the local host’s network interfaces and, if the network number corresponds to one of the hosts’s network interfaces, the corresponding netmask will be used. The netmask may be specified either in standard IP address notation (e.g. 255.255.255.0 or ffff:ffff:ffff:ffff::), or CIDR notation (number of bits, e.g. 24 or 64). A host name may include shell-style wildcards (see the Sx Wildcards section below), but unless the host name command on your machine returns the fully qualified host name, you’ll need to use the fqdn option for wildcards to be useful. Note that sudo only inspects actual network interfaces; this means that IP address 127.0.0.1 (localhost) will never match. Also, the host name “localhost” will only match if that is the actual host name, which is usually only the case for non-networked systems.
digest ::= [A-Fa-f0-9]+ |
[[A-Za-z0-9+/=]+
Digest_Spec ::= "sha224" ‘:’ digest |
"sha256" ‘:’ digest |
"sha384" ‘:’ digest |
"sha512" ‘:’ digest
Cmnd_List ::= Cmnd |
Cmnd ‘,’ Cmnd_List
command name ::= file name |
file name args |
file name ‘""’
Cmnd ::= Digest_Spec? ‘!’* command name |
‘!’* directory |
‘!’* "sudoedit" |
‘!’* Cmnd_Alias
A Cmnd_List is a list of one or more command names, directories, and other aliases. A command name is a fully qualified file name which may include shell-style wildcards (see the Sx Wildcards section below). A simple file name allows the user to run the command with any arguments he/she wishes. However, you may also specify command line arguments (including wildcards). Alternately, you can specify to indicate that the command may only be run without command line arguments. A directory is a fully qualified path name ending in a `/’ When you specify a directory in a Cmnd_List the user will be able to run any file within that directory (but not in any sub-directories therein).
If a Cmnd has associated command line arguments, then the arguments in the Cmnd must match exactly those given by the user on the command line (or match the wildcards if there are any). Note that the following characters must be escaped with a `\’ if they are used in command arguments: `,’ , `:’ , `=’ , `\’ The built-in command “sudoedit ” is used to permit a user to run sudo with the –e option (or as sudoedit ) It may take command line arguments just as a normal command does. Note that “sudoedit ” is a command built into sudo itself and must be specified in sudoers without a leading path.
If a command name is prefixed with a Digest_Spec the command will only match successfully if it can be verified using the specified SHA-2 digest. This may be useful in situations where the user invoking sudo has write access to the command or its parent directory. The following digest formats are supported: sha224, sha256, sha384 and sha512. The string may be specified in either hex or base64 format (base64 is more compact). There are several utilities capable of generating SHA-2 digests in hex format such as openssl, shasum, sha224sum, sha256sum, sha384sum, sha512sum.
For example, using openssl:
$ openssl dgst -sha224 /bin/ls SHA224(/bin/ls)= 118187da8364d490b4a7debbf483004e8f3e053ec954309de2c41a25
It is also possible to use openssl to generate base64 output:
$ openssl dgst -binary -sha224 /bin/ls | openssl base64 EYGH2oNk1JC0p9679IMATo8+BT7JVDCd4sQaJQ==
Command digests are only supported by version 1.8.7 or higher.
Defaults
Certain configuration options may be changed from their default values at run-time via one or more Default_Entry lines. These may affect all users on any host, all users on a specific host, a specific user, a specific command, or commands being run as a specific user. Note that per-command entries may not include command line arguments. If you need to specify arguments, define a Cmnd_Alias and reference that instead.
Default_Type ::= ‘Defaults’ |
‘Defaults’ ‘@’ Host_List |
‘Defaults’ ‘:’ User_List |
‘Defaults’ ‘!’ Cmnd_List |
‘Defaults’ ‘>’ Runas_List
Default_Entry ::= Default_Type Parameter_List
Parameter_List ::= Parameter |
Parameter ‘,’ Parameter_List
Parameter ::= Parameter ‘=’ Value |
Parameter ‘+=’ Value |
Parameter ‘-=’ Value |
‘!’* Parameter
Parameters may be flags integer values, strings or lists Flags are implicitly boolean and can be turned off via the `!’ operator. Some integer, string and list parameters may also be used in a boolean context to disable them. Values may be enclosed in double quotes () when they contain multiple words. Special characters may be escaped with a backslash (`\’ )
Lists have two additional assignment operators, += and -= These operators are used to add to and delete from a list respectively. It is not an error to use the -= operator to remove an element that does not exist in a list.
Defaults entries are parsed in the following order: generic, host and user Defaults first, then runas Defaults and finally command defaults.
See Sx SUDOERS OPTIONS for a list of supported Defaults parameters.
User specification
User_Spec ::= User_List Host_List ‘=’ Cmnd_Spec_List \
(‘:’ Host_List ‘=’ Cmnd_Spec_List)*
Cmnd_Spec_List ::= Cmnd_Spec |
Cmnd_Spec ‘,’ Cmnd_Spec_List
Cmnd_Spec ::= Runas_Spec? SELinux_Spec? Tag_Spec* Cmnd
Runas_Spec ::= ‘(‘ Runas_List? (‘:’ Runas_List)? ‘)’
SELinux_Spec ::= (‘ROLE=role’ | ‘TYPE=type’)
Tag_Spec ::= (‘NOPASSWD:’ | ‘PASSWD:’ | ‘NOEXEC:’ | ‘EXEC:’ |
‘SETENV:’ | ‘NOSETENV:’ | ‘FOLLOW:’ | ‘NOFOLLOW’ |
‘LOG_INPUT:’ | ‘NOLOG_INPUT:’ | ‘LOG_OUTPUT:’ | ‘NOLOG_OUTPUT:’)
A user specification determines which commands a user may run (and as what user) on specified hosts. By default, commands are run as root but this can be changed on a per-command basis.
The basic structure of a user specification is “who where = (as_whom) what” Let’s break that down into its constituent parts:
Runas_Spec
A Runas_Spec determines the user and/or the group that a command may be run as. A fully-specified Runas_Spec consists of two Runas_List s (as defined above) separated by a colon (`:’ ) and enclosed in a set of parentheses. The first Runas_List indicates which users the command may be run as via sudo ‘s –u option. The second defines a list of groups that can be specified via sudo ‘s –g option. If both Runas_List s are specified, the command may be run with any combination of users and groups listed in their respective Runas_List s. If only the first is specified, the command may be run as any user in the list but no –g option may be specified. If the first Runas_List is empty but the second is specified, the command may be run as the invoking user with the group set to any listed in the Runas_List If both Runas_List s are empty, the command may only be run as the invoking user. If no Runas_Spec is specified the command may be run as root and no group may be specified.A Runas_Spec sets the default for the commands that follow it. What this means is that for the entry:
dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/lprm
The user dgb may run /bin/ls /bin/kill and /usr/bin/lprm — but only as operator E.g.,
$ sudo -u operator /bin/ls
It is also possible to override a Runas_Spec later on in an entry. If we modify the entry like so:
dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
Then user dgb is now allowed to run /bin/ls as operator but /bin/kill and /usr/bin/lprm as root
We can extend this to allow dgb to run /bin/ls with either the user or group set to operator
dgb boulder = (operator : operator) /bin/ls, (root) /bin/kill,\
/usr/bin/lprm
Note that while the group portion of the Runas_Spec permits the user to run as command with that group, it does not force the user to do so. If no group is specified on the command line, the command will run with the group listed in the target user’s password database entry. The following would all be permitted by the sudoers entry above:
$ sudo -u operator /bin/ls $ sudo -u operator -g operator /bin/ls $ sudo -g operator /bin/ls
In the following example, user tcm may run commands that access a modem device file with the dialer group.
tcm boulder = (:dialer) /usr/bin/tip, /usr/bin/cu,\
/usr/local/bin/minicom
Note that in this example only the group will be set, the command still runs as user tcm E.g.
$ sudo -g dialer /usr/bin/cu
Multiple users and groups may be present in a Runas_Spec in which case the user may select any combination of users and groups via the –u and –g options. In this example:
alan ALL = (root, bin : operator, system) ALL
user alan may run any command as either user root or bin, optionally setting the group to operator or system.
SELinux_Spec
On systems with SELinux support, sudoers entries may optionally have an SELinux role and/or type associated with a command. If a role or type is specified with the command it will override any default values specified in sudoers A role or type specified on the command line, however, will supersede the values in sudoersTag_Spec
A command may have zero or more tags associated with it. There are ten possible tag values: NOPASSWD PASSWD NOEXEC EXEC SETENV NOSETENV FOLLOW NOFOLLOW LOG_INPUT NOLOG_INPUT LOG_OUTPUT and NOLOG_OUTPUT Once a tag is set on a Cmnd subsequent Cmnd s in the Cmnd_Spec_List inherit the tag unless it is overridden by the opposite tag (in other words, PASSWD overrides NOPASSWD and NOEXEC overrides EXEC )- NOPASSWD and PASSWD
-
By default, sudo requires that a user authenticate him or herself before running a command. This behavior can be modified via the NOPASSWD tag. Like a Runas_Spec the NOPASSWD tag sets a default for the commands that follow it in the Cmnd_Spec_List Conversely, the PASSWD tag can be used to reverse things. For example:
ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
would allow the user ray to run /bin/kill /bin/ls and /usr/bin/lprm as root on the machine rushmore without authenticating himself. If we only want ray to be able to run /bin/kill without a password the entry would be:
ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
Note, however, that the PASSWD tag has no effect on users who are in the group specified by the exempt_group option.
By default, if the NOPASSWD tag is applied to any of the entries for a user on the current host, he or she will be able to run “sudo -l ” without a password. Additionally, a user may only run “sudo -v ” without a password if the NOPASSWD tag is present for all a user’s entries that pertain to the current host. This behavior may be overridden via the verifypw and listpw options.
- NOEXEC and EXEC
-
If sudo has been compiled with noexec support and the underlying operating system supports it, the NOEXEC tag can be used to prevent a dynamically-linked executable from running further commands itself.
In the following example, user aaron may run /usr/bin/more and /usr/bin/vi but shell escapes will be disabled.
aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
See the Sx Preventing shell escapes section below for more details on how NOEXEC works and whether or not it will work on your system.
- SETENV and NOSETENV
-
These tags override the value of the setenv option on a per-command basis. Note that if SETENV has been set for a command, the user may disable the env_reset option from the command line via the –E option. Additionally, environment variables set on the command line are not subject to the restrictions imposed by env_check env_delete or env_keep As such, only trusted users should be allowed to set variables in this manner. If the command matched is ALL the SETENV tag is implied for that command; this default may be overridden by use of the NOSETENV tag.
- FOLLOW and NOFOLLOW
- Starting with version 1.8.10p3-1+deb8u3, sudoedit will not follow symbolic links when opening files unless the sudoedit_follow option is enabled. The FOLLOW and NOFOLLOW tags override the value of sudoedit_follow and can be used to permit (or deny) the editing of symbolic links on a per-command basis. These tags are only effective for the sudoedit command and are ignored for all other commands.
- LOG_INPUT and NOLOG_INPUT
-
These tags override the value of the log_input option on a per-command basis. For more information, see the description of log_input in the Sx SUDOERS OPTIONS section below.
- LOG_OUTPUT and NOLOG_OUTPUT
-
These tags override the value of the log_output option on a per-command basis. For more information, see the description of log_output in the Sx SUDOERS OPTIONS section below.
Wildcards
sudo allows shell-style wildcards (aka meta or glob characters) to be used in host names, path names and command line arguments in the sudoers file. Wildcard matching is done via the glob(3) and fnmatch(3) functions as specified by St -p1003.1 . Note that these are not regular expressions.- *
- Matches any set of zero or more characters.
- ?
- Matches any single character.
- […]
- Matches any character in the specified range.
- [!…]
- Matches any character not in the specified range.
- \x
- For any character `x’ evaluates to `x’ This is used to escape special characters such as: `*’ , `?’ , `[‘ , and `]’
Character classes may also be used if your system’s (3) and fnmatch(3) functions support them. However, because the `:’ character has special meaning in sudoers it must be escaped. For example:
/bin/ls [[:alpha:]]*
Would match any file name beginning with a letter.
Note that a forward slash (`/’ ) will not be matched by wildcards used in the path name. This is to make a path like:
/usr/bin/*
match /usr/bin/who but not /usr/bin/X11/xterm
When matching the command line arguments, however, a slash does get matched by wildcards since command line arguments may contain arbitrary strings and not just path names.
Wildcards in command line arguments should be used with care. Because command line arguments are matched as a single, concatenated string, a wildcard such as `?’ or `*’ can match multiple words. For example, while a sudoers entry like:
%operator ALL = /bin/cat /var/log/messages*
will allow command like:
$ sudo cat /var/log/messages.1
It will also allow:
$ sudo cat /var/log/messages /etc/shadow
which is probably not what was intended.
Exceptions to wildcard rules
The following exceptions apply to the above rules:- If the empty string is the only command line argument in the sudoers entry it means that command is not allowed to be run with any arguments.
- sudoedit
- Command line arguments to the sudoedit built-in command should always be path names, so a forward slash (`/’ ) will not be matched by a wildcard.
Including other files from within sudoers
It is possible to include other sudoers files from within the sudoers file currently being parsed using the #include and #includedir directives.This can be used, for example, to keep a site-wide sudoers file in addition to a local, per-machine file. For the sake of this example the site-wide sudoers will be /etc/sudoers and the per-machine one will be /etc/sudoers.local To include /etc/sudoers.local from within /etc/sudoers we would use the following line in /etc/sudoers
#include /etc/sudoers.local
When sudo reaches this line it will suspend processing of the current file (/etc/sudoers ) and switch to /etc/sudoers.local Upon reaching the end of /etc/sudoers.local the rest of /etc/sudoers will be processed. Files that are included may themselves include other files. A hard limit of 128 nested include files is enforced to prevent include file loops.
If the path to the include file is not fully-qualified (does not begin with a `/’ , it must be located in the same directory as the sudoers file it was included from. For example, if /etc/sudoers contains the line:
#include sudoers.local
the file that will be included is /etc/sudoers.local
The file name may also include the %h escape, signifying the short form of the host name. In other words, if the machine’s host name is “xerxes” then
#include /etc/sudoers.%h
will cause sudo to include the file /etc/sudoers.xerxes
The #includedir directive can be used to create a sudo.d directory that the system package manager can drop sudoers rules into as part of package installation. For example, given:
#includedir /etc/sudoers.d
sudo will read each file in /etc/sudoers.d skipping file names that end in `~’ or contain a `.’ character to avoid causing problems with package manager or editor temporary/backup files. Files are parsed in sorted lexical order. That is, /etc/sudoers.d/01_first will be parsed before /etc/sudoers.d/10_second Be aware that because the sorting is lexical, not numeric, /etc/sudoers.d/1_whoops would be loaded after /etc/sudoers.d/10_second Using a consistent number of leading zeroes in the file names can be used to avoid such problems.
Note that unlike files included via #include visudo will not edit the files in a #includedir directory unless one of them contains a syntax error. It is still possible to run visudo with the –f flag to edit the files directly.
Other special characters and reserved words
The pound sign (`#’ ) is used to indicate a comment (unless it is part of a #include directive or unless it occurs in the context of a user name and is followed by one or more digits, in which case it is treated as a uid). Both the comment character and any text after it, up to the end of the line, are ignored.The reserved word ALL is a built-in alias that always causes a match to succeed. It can be used wherever one might otherwise use a Cmnd_Alias User_Alias Runas_Alias or Host_Alias You should not try to define your own alias called ALL as the built-in alias will be used in preference to your own. Please note that using ALL can be dangerous since in a command context, it allows the user to run any command on the system.
An exclamation point (`!’ ) can be used as a logical not operator in a list or alias as well as in front of a Cmnd This allows one to exclude certain values. For the `!’ operator to be effective, there must be something for it to exclude. For example, to match all users except for root one would use:
ALL,!root
If the ALL is omitted, as in:
!root
it would explicitly deny root but not match any other users. This is different from a true “negation” operator.
Note, however, that using a `!’ in conjunction with the built-in ALL alias to allow a user to run “all but a few” commands rarely works as intended (see Sx SECURITY NOTES below).
Long lines can be continued with a backslash (`\’ ) as the last character on the line.
White space between elements in a list as well as special syntactic characters in a User Specification Po `=’ , `:’ , `(‘ , `)’ Pc is optional.
The following characters must be escaped with a backslash (`\’ ) when used as part of a word (e.g. a user name or host name): `!’ , `=’ , `:’ , `,’ , `(‘ , `)’ , `\’
SUDOERS OPTIONS
sudo ‘s behavior can be modified by Default_Entry lines, as explained earlier. A list of all supported Defaults parameters, grouped by type, are listed below.Boolean Flags
- always_set_home
- If enabled, sudo will set the HOME environment variable to the home directory of the target user (which is root unless the –u option is used). This effectively means that the –H option is always implied. Note that HOME is already set when the env_reset option is enabled, so always_set_home is only effective for configurations where either env_reset is disabled or HOME is present in the env_keep list. This flag is off by default.
- authenticate
- If set, users must authenticate themselves via a password (or other means of authentication) before they may run commands. This default may be overridden via the PASSWD and NOPASSWD tags. This flag is on by default.
- closefrom_override
- If set, the user may use sudo ‘s –C option which overrides the default starting point at which sudo begins closing open file descriptors. This flag is off by default.
- compress_io
- If set, and sudo is configured to log a command’s input or output, the I/O logs will be compressed using zlib This flag is on by default when sudo is compiled with zlib support.
- use_netgroups
- If set, netgroups (prefixed with `+’ ) , may be used in place of a user or host. For LDAP-based sudoers, netgroup support requires an expensive substring match on the server. If netgroups are not needed, this option can be disabled to reduce the load on the LDAP server. This flag is on by default.
- exec_background
-
By default,
sudo
runs a command as the foreground process as long as
sudo
itself is running in the foreground.
When the
exec_background
flag is enabled and the command is being run in a pty (due to I/O logging
or the
use_pty
flag), the command will be run as a background process.
Attempts to read from the controlling terminal (or to change terminal
settings) will result in the command being suspended with the
SIGTTIN
signal (or
SIGTTOU
in the case of terminal settings).
If this happens when
sudo
is a foreground process, the command will be granted the controlling terminal
and resumed in the foreground with no user intervention required.
The advantage of initially running the command in the background is that
sudo
need not read from the terminal unless the command explicitly requests it.
Otherwise, any terminal input must be passed to the command, whether it
has required it or not (the kernel buffers terminals so it is not possible
to tell whether the command really wants the input).
This is different from historic
sudo
behavior or when the command is not being run in a pty.
For this to work seamlessly, the operating system must support the automatic restarting of system calls. Unfortunately, not all operating systems do this by default, and even those that do may have bugs. For example, Mac OS X fails to restart the Fn tcgetattr and Fn tcsetattr system calls (this is a bug in Mac OS X). Furthermore, because this behavior depends on the command stopping with the SIGTTIN or SIGTTOU signals, programs that catch these signals and suspend themselves with a different signal (usually SIGTOP will not be automatically foregrounded. Some versions of the linux su(1) command behave this way.
This setting is only supported by version 1.8.7 or higher. It has no effect unless I/O logging is enabled or the use_pty flag is enabled.
- env_editor
- If set, visudo will use the value of the EDITOR or VISUAL environment variables before falling back on the default editor list. Note that this may create a security hole as it allows the user to run any arbitrary command as root without logging. A safer alternative is to place a colon-separated list of editors in the editor variable. visudo will then only use the EDITOR or VISUAL if they match a value specified in editor This flag is on by default.
- env_reset
- If set, sudo will run the command in a minimal environment containing the TERM PATH HOME MAIL SHELL LOGNAME USER USERNAME and SUDO_* variables. Any variables in the caller’s environment that match the env_keep and env_check lists are then added, followed by any variables present in the file specified by the env_file option (if any). The default contents of the env_keep and env_check lists are displayed when sudo is run by root with the –V option. If the secure_path option is set, its value will be used for the PATH environment variable. This flag is on by default.
- fast_glob
- Normally, sudo uses the glob(3) function to do shell-style globbing when matching path names. However, since it accesses the file system, glob(3) can take a long time to complete for some patterns, especially when the pattern references a network file system that is mounted on demand (auto mounted). The fast_glob option causes sudo to use the fnmatch(3) function, which does not access the file system to do its matching. The disadvantage of fast_glob is that it is unable to match relative path names such as ./ls or ../bin/ls This has security implications when path names that include globbing characters are used with the negation operator, `!’ , as such rules can be trivially bypassed. As such, this option should not be used when sudoers contains rules that contain negated path names which include globbing characters. This flag is off by default.
- fqdn
-
Set this flag if you want to put fully qualified host names in the
sudoers
file when the local host name (as returned by the
hostname
command) does not contain the domain name.
In other words, instead of myhost you would use myhost.mydomain.edu.
You may still use the short form if you wish (and even mix the two).
This option is only effective when the
“canonical”
host name, as returned by the
Fn getaddrinfo
or
Fn gethostbyname
function, is a fully-qualified domain name.
This is usually the case when the system is configured to use DNS
for host name resolution.
If the system is configured to use the /etc/hosts file in preference to DNS, the “canonical” host name may not be fully-qualified. The order that sources are queried for host name resolution is usually specified in the /etc/nsswitch.conf /etc/netsvc.conf /etc/host.conf or, in some cases, /etc/resolv.conf file. In the /etc/hosts file, the first host name of the entry is considered to be the “canonical” name; subsequent names are aliases that are not used by sudoers For example, the following hosts file line for the machine “xyzzy” has the fully-qualified domain name as the “canonical” host name, and the short version as an alias.
192.168.1.1 xyzzy.sudo.ws xyzzy
If the machine’s hosts file entry is not formatted properly, the
fqdn option will not be effective if it is queried before DNS.Beware that when using DNS for host name resolution, turning on fqdn requires sudoers to make DNS lookups which renders sudo unusable if DNS stops working (for example if the machine is disconnected from the network). Also note that just like with the hosts file, you must use the “canonical” name as DNS knows it. That is, you may not use a host alias Po CNAME entry Pc due to performance issues and the fact that there is no way to get all aliases from DNS.
This flag is on by default.
- ignore_dot
- If set, sudo will ignore "." or "" (both denoting current directory) in the PATH environment variable; the PATH itself is not modified. This flag is off by default.
- ignore_local_sudoers
- If set via LDAP, parsing of /etc/sudoers will be skipped. This is intended for Enterprises that wish to prevent the usage of local sudoers files so that only LDAP is used. This thwarts the efforts of rogue operators who would attempt to add roles to /etc/sudoers When this option is present, /etc/sudoers does not even need to exist. Since this option tells sudo how to behave when no specific LDAP entries have been matched, this sudoOption is only meaningful for the cn=defaults section. This flag is off by default.
- insults
- If set, sudo will insult users when they enter an incorrect password. This flag is off by default.
- log_host
- If set, the host name will be logged in the (non-syslog) sudo log file. This flag is off by default.
- log_input
-
If set,
sudo
will run the command in a
pseudo tty
and log all user input.
If the standard input is not connected to the user’s tty, due to
I/O redirection or because the command is part of a pipeline, that
input is also captured and stored in a separate log file.
Input is logged to the directory specified by the iolog_dir option Po /var/log/sudo-io by default Pc using a unique session ID that is included in the normal sudo log line, prefixed with “TSID= ” The iolog_file option may be used to control the format of the session ID.
Note that user input may contain sensitive information such as passwords (even if they are not echoed to the screen), which will be stored in the log file unencrypted. In most cases, logging the command output via log_output is all that is required.
- log_output
- If set, sudo will run the command in a pseudo tty and log all output that is sent to the screen, similar to the