sudoers (5) Linux Manual Page
Sudo 1.9.9
Name
sudoers – default sudo security policy plugin
Description
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 plugins to load. If no sudo.conf5 file is present, or if it contains no Plugin lines, sudoers will be used for auditing, policy decisions and I/O logging. To explicitly configure sudo.conf5 to use the sudoers plugin, the following configuration can be used.
Plugin sudoers_audit sudoers.so 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. Plugin arguments, if any, should be listed after the path to the plugin (i.e., after sudoers.so ) The arguments are only effective for the plugin that opens (and parses) the sudoers file. For sudo version 1.9.1 and higher, this is the sudoers_audit plugin. For older versions, it is the sudoers_policy plugin. Multiple arguments may be specified, separated by white space. For example:
Plugin sudoers_audit sudoers.so sudoers_mode=0400 error_recovery=false
The following plugin arguments are supported:
error_recovery=bool- The error_recovery argument can be used to control whether
sudoersshould attempt to recover from syntax errors in the sudoers file. If set to true (the default),sudoerswill try to recover from a syntax error by discarding the portion of the line that contains the error until the end of the line. A value of false will disable error recovery. Prior to version 1.9.3, no error recovery was performed. 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=user-ID- 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=group-ID- 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.
User Authentication
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 no mail will be sent if an unauthorized user tries to run sudo with the –l or –v option unless there is an authentication error and either the mail_always or mail_badpass flags are enabled. This allows users to determine for themselves whether or not they are allowed to use sudo By default, all attempts to run sudo (successful or not) are logged, regardless of whether or not mail is sent. 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 file 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 user-ID that was used to authenticate, the terminal session ID, the start time of the session leader (or parent process) 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 timestamp_timeout option Pc . By default, sudoers uses a separate record for each terminal, which means that a user’s login sessions are authenticated separately. The timestamp_type option can be used to select the type of time stamp record sudoers will use.
Logging
By default, sudoers logs both successful and unsuccessful attempts (as well as errors). The log_allowed and log_denied flags can be used to control this behavior. Messages can be logged to syslog(3), a log file, or both. The default is to log to syslog(3) but this is configurable via the syslog and logfile settings. See Sx LOG FORMAT for a description of the log file format. sudoers is also capable of running a command in a pseudo-terminal and logging all input and/or output. The standard input, standard output, and standard error can be logged even when not associated with a terminal. I/O logging is not on by default but can be enabled using the log_input and log_output options as well as the LOG_INPUT and LOG_OUTPUT command tags. See Sx I/O LOG FILES for details on how I/O log files are stored. Starting with version 1.9, the log_servers setting may be used to send event and I/O log data to a remote server running sudo_logsrvd or another service that implements the protocol described by sudo_logsrv.proto5.
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 flag 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 HOME MAIL SHELL LOGNAME and USER environment variables are initialized based on the target user and the SUDO_* variables are set based on the invoking user. Additional variables, such as DISPLAY PATH and TERM are preserved from the invoking user’s environment if permitted by the env_check or env_keep options. A few environment variables are treated specially. If the PATH and TERM variables are not preserved from the user’s environment, they will be set to default values. The LOGNAME and USER are handled as a single entity. If one of them is preserved (or removed) from the user’s environment, the other will be as well. If LOGNAME and USER are to be preserved but only one of them is present in the user’s environment, the other will be set to the same value. This avoids an inconsistent environment where one of the variables describing the user name is set to the invoking user and one is set to the target user. Environment variables with a value beginning with () are removed unless both the name and value parts are matched by env_keep or env_check as they may be interpreted as functions by the bash shell. Prior to version 1.8.11, such variables were always removed. If, however, the env_reset flag is disabled, any variables not explicitly denied by the env_check and env_delete options are allowed and their values are inherited from the invoking process. Prior to version 1.8.21, environment variables with a value beginning with () were always removed. Beginning with version 1.8.21, a pattern in env_delete is used to match bash shell functions instead. Since it is not possible to block all potentially dangerous environment variables, use of the default env_reset behavior is encouraged. Environment variables specified by env_check env_delete or env_keep may include one or more `*’ characters which will match zero or more characters. No other wildcard characters are supported.
By default, environment variables are matched by name.
However, if the pattern includes an equal sign
(`='
)
both the variables name and value must match.
For example, a
bash
shell function could be matched as follows:
env_keep += "BASH_FUNC_my_func%%=()*"
Without the “=()* ” suffix, this would not match, as bash shell functions are not preserved by default. The complete list of environment variables that are preserved or removed, as modified by global Defaults parameters in sudoers is displayed when sudo is run by root with the –V option. Please note that the list of environment variables to remove varies based on the operating system sudo is running on. Other sudoers options may influence the command environment, such as always_set_home secure_path set_logname and set_home On systems that support PAM where the pam_env module is enabled for sudo variables in the PAM environment may be merged in to the environment. If a variable in the PAM environment is already present in the user’s environment, the value will only be overridden if the variable was not preserved by sudoers. When env_reset is enabled, variables preserved from the invoking user’s environment by the env_keep list take precedence over those in the PAM environment. When env_reset is disabled, variables present the invoking user’s environment take precedence over those in the PAM environment unless they match a pattern in the env_delete list. Note that the dynamic linker on most operating systems will remove variables that can control dynamic linking from the environment of set-user-ID 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 the –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 unless permitted by env_keep or env_check described above. Finally, the restricted_env_file and env_file files are applied, if present. The variables in restricted_env_file are applied first and are subject to the same restrictions as the invoking user’s environment, as detailed above. The variables in env_file are applied last and are not subject to these restrictions. In both cases, variables present in the files will only be set to their specified values if 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 file 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.
Resource limits
By default, sudoers uses the operating system’s native method of setting resource limits for the target user. On Linux systems, resource limits are usually set by the pam_limits.so PAM module. On some BSD systems, the /etc/login.conf file specifies resource limits for the user. On AIX systems, resource limits are configured in the /etc/security/limits file. If there is no system mechanism to set per-user resource limits, the command will run with the same limits as the invoking user. The one exception to this is the core dump file size, which is set by sudoers to 0 by default. Disabling core dumps by default makes it possible to avoid potential security problems where the core file is treated as trusted input.
Resource limits may also be set in the sudoers file itself, in which case they override those set by the system. See the rlimit_as, rlimit_core, rlimit_cpu, rlimit_data, rlimit_fsize, rlimit_locks, rlimit_memlock, rlimit_nofile, rlimit_nproc, rlimit_rss, rlimit_stack options described below. Resource limits in sudoers may be specified in one of the following formats:
“value”- Both the soft and hard resource limits are set to the same value. The special value “infinity” can be used to indicate that the value is unlimited.
“soft,hard”- Two comma-separated values. The soft limit is set to the first value and the hard limit is set to the second. Both values must either be enclosed in a set of double quotes, or the comma must be escaped with a backslash (`\’ ) The special value “infinity” may be used in place of either value.
“default”- The default resource limit for the user will be used. This may be a user-specific value (see above) or the value of the resource limit when
sudowas invoked for systems that don’t support per-user limits. “user”- The invoking user’s resource limits will be preserved when running the command.
For example, to restore the historic core dump file size behavior, a line like the following may be used.
Defaults rlimit_core=default
Resource limits in sudoers are only supported by version 1.8.7 or higher.
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 Beginning with sudo 1.9.0, Cmd_Alias may be used in place of Cmnd_Alias if desired.
Alias ::= 'User_Alias' User_Alias_Spec (':' User_Alias_Spec)* |
'Runas_Alias' Runas_Alias_Spec (':' Runas_Alias_Spec)* |
'Host_Alias' Host_Alias_Spec (':' Host_Alias_Spec)* |
'Cmnd_Alias' Cmnd_Alias_Spec (':' Cmnd_Alias_Spec)* |
'Cmd_Alias' Cmnd_Alias_Spec (':' Cmnd_Alias_Spec)*
User_Alias ::= NAME
User_Alias_Spec ::= User_Alias '=' User_List
Runas_Alias ::= NAME
Runas_Alias_Spec ::= Runas_Alias '=' Runas_List
Host_Alias ::= NAME
Host_Alias_Spec ::= Host_Alias '=' Host_List
Cmnd_Alias ::= NAME
Cmnd_Alias_Spec ::= Cmnd_Alias '=' 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
It is a syntax error to redefine an existing alias It is possible to use the same name for aliases of different types, but this is not recommended.
The definitions of what constitutes a valid alias member follow.
User_List ::= User | User ',' User_List User ::= '!'* user name | '!'* #user-ID | '!'* %group | '!'* %#group-ID | '!'* +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. User netgroups are matched using the user and domain members only; the host member is not used when matching.
A user name user-ID group group-ID 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., 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 Name [at] FULLY.QUALIFIED.DOMAIN"
- 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 | '!'* #user-ID | '!'* %group | '!'* %#group-ID | '!'* %: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 user (group) ID are considered to be distinct. If you wish to match all user names with the same user-ID (e.g., root and toor), you can use a user-ID instead of a name (#0 in the example given). Note that the user-ID or group-ID specified in a Runas_Member need not be listed in the password or group database.
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. Host netgroups are matched using the host (both qualified and unqualified) and domain members only; the user member is not used when matching. If you specify a network number without a netmask, 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, will use the netmask of that interface. 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 flag 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 Digest_List ::= Digest_Spec | Digest_Spec ',' Digest_List Cmnd_List ::= Cmnd | Cmnd ',' Cmnd_List command name ::= file name | file name args | file name '""' Edit_Spec ::= "sudoedit" file name+ Cmnd ::= Digest_List? '!'* command name | '!'* directory | '!'* Edit_Spec | '!'* 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 they wish. 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 the sudoers file without a leading path. If a leading path is present, for example /usr/bin/sudoedit the path name will be silently converted to “sudoedit ” A fully-qualified path for sudoedit is treated as an error by visudo
A command name may be preceded by a Digest_List a comma-separated list of one or more Digest_Spec entries. If a Digest_List is present, the command will only match successfully if it can be verified using one of the SHA-2 digests in the list. Starting with version 1.9.0, the ALL reserved word can be used in conjunction with a Digest_List 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==
Warning, if the user has write access to the command itself (directly or via a sudo command), it may be possible for the user to replace the command after the digest check has been performed but before the command is executed. A similar race condition exists on systems that lack the Fn fexecve system call when the directory in which the command is located is writable by the user. See the description of the fdexec setting for more information on how sudo executes commands that have an associated digest.
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 (`\’ )
To include a literal backslash character in a command line argument you must escape the backslash twice. For example, to match `
’ as part of a command line argument, you must use `\\n’ in the sudoers file. This is due to there being two levels of escaping, one in the sudoers parser itself and another when command line arguments are matched by the fnmatch(3) function.
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, user, and runas Defaults first, then command defaults. If there are multiple Defaults settings of the same type, the last matching setting is used. The following Defaults settings are parsed before all others since they may affect subsequent entries: fqdn group_plugin runas_default sudoers_locale
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? Option_Spec* Tag_Spec* Cmnd
Runas_Spec ::= '(' Runas_List? (':' Runas_List)? ')'
Option_Spec ::= (SELinux_Spec | Date_Spec | Timeout_Spec | Chdir_Spec | Chroot_Spec)
Option_Spec ::= (Date_Spec | Timeout_Spec | Chdir_Spec | Chroot_Spec)
SELinux_Spec ::= ('ROLE=role' | 'TYPE=type')
Date_Spec ::= ('NOTBEFORE=timestamp' | 'NOTAFTER=timestamp')
Timeout_Spec ::= 'TIMEOUT=timeout'
Chdir_Spec ::= 'CWD=directory'
Chroot_Spec ::= 'CHROOT=directory'
Tag_Spec ::= ('EXEC:' | 'NOEXEC:' | 'FOLLOW:' | 'NOFOLLOW' |
'LOG_INPUT:' | 'NOLOG_INPUT:' | 'LOG_OUTPUT:' |
'NOLOG_OUTPUT:' | 'MAIL:' | 'NOMAIL:' | 'INTERCEPT:' |
'NOINTERCEPT:' | 'PASSWD:' | 'NOPASSWD:' | 'SETENV:' |
'NOSETENV:')
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 the –u option. The second defines a list of groups that may be specified via the –g option (in addition to any of the target user’s groups). 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 and, optionally, with any group the target user belongs to. 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 and the group, if specified, must be one that the invoking user is a member of. If no Runas_Spec is specified, the command may only be run as root and the group, if specified, must be one that root is a member of.
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 on the host boulder — 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.
Option_Spec
A Cmnd may have zero or more options associated with it. Options may consist of SELinux roles and/or types, start and/or end dates and command timeouts. Once an option is set for a Cmnd subsequent Cmnd s in the Cmnd_Spec_List inherit that option unless it is overridden by another option. Note that the option names are reserved words in sudoers This means that none of the valid option names (see below) can be used when declaring an alias.
SELinux_Spec
On systems with SELinux support, sudoers file entries may optionally have an SELinux role and/or type associated with a command. This can be used to implement a form of role-based access control (RBAC). 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 sudoers
Date_Spec
sudoers rules can be specified with a start and end date via the NOTBEFORE and NOTAFTER settings. The time stamp must be specified in Generalized Time as defined by RFC 4517. The format is effectively yyyymmddHHMMSSZ where the minutes and seconds are optional. The `Z’ suffix indicates that the time stamp is in Coordinated Universal Time (UTC). It is also possible to specify a timezone offset from UTC in hours and minutes instead of a `Z’ For example, `-0500′ would correspond to Eastern Standard time in the US. As an extension, if no `Z’ or timezone offset is specified, local time will be used.
The following are all valid time stamps:
20170214083000Z 2017021408Z 20160315220000-0500 20151201235900
Timeout_Spec
A command may have a timeout associated with it. If the timeout expires before the command has exited, the command will be terminated. The timeout may be specified in combinations of days, hours, minutes, and seconds with a single-letter case-insensitive suffix that indicates the unit of time. For example, a timeout of 7 days, 8 hours, 30 minutes, and 10 seconds would be written as 7d8h30m10s If a number is specified without a unit, seconds are assumed. Any of the days, minutes, hours, or seconds may be omitted. The order must be from largest to smallest unit and a unit may not be specified more than once.
The following are all valid timeout values: 7d8h30m10s 14d 8h30m 600s 3600 The following are invalid timeout values: 12m2w1d 30s10m4h 1d2d3h
This setting is only supported by version 1.8.20 or higher.
Chdir_Spec
The working directory that the command will be run in can be specified using the CWD setting. The Fa directory must be a fully-qualified path name beginning with a `/’ or `~’ character, or the special value “*” A value of “*” indicates that the user may specify the working directory by running sudo with the –D option. By default, commands are run from the invoking user’s current working directory, unless the –i option is given. Path names of the form ~user/path/name are interpreted as being relative to the named user’s home directory. If the user name is omitted, the path will be relative to the runas user’s home directory.
This setting is only supported by version 1.9.3 or higher.
Chroot_Spec
The root directory that the command will be run in can be specified using the CHROOT setting. The Fa directory must be a fully-qualified path name beginning with a `/’ or `~’ character, or the special value “*” A value of “*” indicates that the user may specify the root directory by running sudo with the –R option. This setting can be used to run the command in a chroot(2) “sandbox” similar to the chroot(8) utility. Path names of the form ~user/path/name are interpreted as being relative to the named user’s home directory. If the user name is omitted, the path will be relative to the runas user’s home directory.
This setting is only supported by version 1.9.3 or higher.
Tag_Spec
A command may have zero or more tags associated with it. The following tag values are supported: EXEC NOEXEC FOLLOW NOFOLLOW LOG_INPUT NOLOG_INPUT LOG_OUTPUT NOLOG_OUTPUT MAIL NOMAIL INTERCEPT NOINTERCEPT PASSWD NOPASSWD SETENV and NOSETENV 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 )
- EXEC
andNOEXEC - If
sudohas been compiled with noexec support and the underlying operating system supports it, theNOEXECtag can be used to prevent a dynamically-linked executable from running further commands itself.In the following example, user
aaronmay 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
NOEXECworks and whether or not it will work on your system. - FOLLOW
andNOFOLLOW - Starting with version 1.8.15,
sudoeditwill not open a file that is a symbolic link unless the sudoedit_follow flag 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
andNOLOG_INPUT - These tags override the value of the log_input flag on a per-command basis. For more information, see the description of log_input in the Sx SUDOERS OPTIONS section below.
- LOG_OUTPUT
andNOLOG_OUTPUT - These tags override the value of the log_output flag on a per-command basis. For more information, see the description of log_output in the Sx SUDOERS OPTIONS section below.
- MAIL
andNOMAIL - These tags provide fine-grained control over whether mail will be sent when a user runs a command by overriding the value of the mail_all_cmnds flag on a per-command basis. They have no effect when
sudois run with the –lor –voptions. A NOMAIL tag will also override the mail_always and mail_no_perms options. For more information, see the descriptions of mail_all_cmnds mail_always and mail_no_perms in the Sx SUDOERS OPTIONS section below. - PASSWD
andNOPASSWD - By default,
sudorequires that a user authenticate before running a command. This behavior can be modified via theNOPASSWDtag. Like aRunas_SpectheNOPASSWDtag sets a default for the commands that follow it in theCmnd_Spec_ListConversely, thePASSWDtag can be used to reverse things. For example:ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
would allow the user
rayto run /bin/kill /bin/ls and /usr/bin/lprm asrooton the machine “rushmore” without authenticating himself. If we only wantrayto 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
PASSWDtag has no effect on users who are in the group specified by the exempt_group setting.By default, if the
NOPASSWDtag is applied to any of a user’s entries for the current host, the user will be able to run “sudo -l” without a password. Additionally, a user may only run “sudo -v” without a password if all of the user’s entries for the current host have theNOPASSWDtag. This behavior may be overridden via the verifypw and listpw options. - SETENV
andNOSETENV - These tags override the value of the setenv flag on a per-command basis. Note that if
SETENVhas been set for a command, the user may disable the env_reset flag from the command line via the –Eoption. 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 isALLtheSETENVtag is implied for that command; this default may be overridden by use of theNOSETENVtag. - INTERCEPT
andNOINTERCEPT - If
sudohas been compiled with intercept support and the underlying operating system supports it, theINTERCEPTtag can be used to cause programs spawned by a command to be validated against sudoers and logged just like they would be if run throughsudodirectly. This is useful in conjunction with commands that allow shell escapes such as editors, shells, and paginators.In the following example, user
chuckmay run any command on the machine “research” in intercept mode.chuck research = INTERCEPT: ALL
See the Sx Preventing shell escapes section below for more details on how
INTERCEPTworks and whether or not it will work on your system.
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 .
*- Matches any set of zero or more characters (including white space).
?- Matches any single character (including white space).
[…]- Matches any character in the specified range.
[!…]- Matches any character not in the specified range.
