also supports logging a command’s input and output
streams.
I/O logging is not on by default but can be enabled using
thelog_input

andlog_output

Defaults flags as well as theLOG_INPUT

andLOG_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 wayssudoers

can deal with environment variables.

By default, theenv_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 theTERM

PATH

HOME

MAIL

SHELL

LOGNAME

USER

USERNAME

andSUDO_*

variables
in addition to variables from the invoking process permitted by theenv_check

andenv_keep

options.
This is effectively a whitelist
for environment variables.

If, however, theenv_reset

option is disabled, any variables not
explicitly denied by theenv_check

andenv_delete

options are
inherited from the invoking process.
In this case,env_check

andenv_delete

behave like a blacklist.
Since it is not possible
to blacklist all potentially dangerous environment variables, use
of the defaultenv_reset

behavior is encouraged.

In all cases, environment variables with a value beginning with()

are removed as they could be interpreted asbash

functions.
The list of environment variables thatsudo

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, includingsudo

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 beforesudo

even begins execution
and, as such, it is not possible forsudo

to preserve them.

As a special case, ifsudo ‘s

-i

option (initial login) is
specified,sudoers

will initialize the environment regardless
of the value ofenv_reset

TheDISPLAY

PATH

andTERM

variables remain unchanged;HOME

MAIL

SHELL

USER

andLOGNAME

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 theenv_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

Thesudoers

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).

Thesudoers

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 ofproduction rules

E.g.,

symbol ::= definition | alternate1 | alternate2 …

Eachproduction 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).

operators negate the value of
the item; an even number just cancel each other out.

Auser name

uid

group

gid

netgroup

nonunix_group

ornonunix_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 actualnonunix_group

andnonunix_gid

syntax depends on
the underlying group provider plugin (see thegroup_plugin

description below).
For instance, the QAS AD plugin supports the following formats:

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).

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

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 runwithout

command line arguments.
A directory is a
fully qualified path name ending in a
`/’

When you specify a directory in aCmnd_List

the user will be able to run any file within that directory
(but not in any sub-directories therein).

If aCmnd

has associated command line arguments, then the arguments
in theCmnd

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 special command
“sudoedit

”

is used to permit a user to runsudo

with the
-e

option (or assudoedit )

It may take command line arguments just as a normal command does.

Defaults

Certain configuration options may be changed from their default
values at run-time via one or moreDefault_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 aCmnd_Alias

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:

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 slashdoes

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 thesudoers

entry it means that command is not allowed to be run withany

arguments.

sudoedit

Command line arguments to thesudoedit

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 othersudoers

files from within thesudoers

file currently being parsed using the#include

and#includedir

directives.

This can be used, for example, to keep a site-widesudoers

file in addition to a local, per-machine file.
For the sake of this example the site-widesudoers

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

Whensudo

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 causesudo

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 dropsudoers

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 loadedafter

/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 runvisudo

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 wordALL

is a built-inalias

that always causes a match to succeed.
It can be used wherever one might otherwise use aCmnd_Alias

User_Alias

Runas_Alias

orHost_Alias

You should not try to define your ownalias

calledALL

as the built-in alias will be used in preference to your own.
Please note that usingALL

can be dangerous since in a command context, it allows the user to runany

command on the system.

An exclamation point
(`!’

)

can be used as a logicalnot

operator in a list oralias

as well as in front of aCmnd

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 theALL

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-inALL

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 aUser 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 byDefault_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 theHOME

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 thatHOME

is already set when the theenv_reset

option is enabled, soalways_set_home

is only effective for configurations where eitherenv_reset

is disabled orHOME

is present in theenv_keep

list.
This flag isoff

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 thePASSWD

andNOPASSWD

tags.
This flag ison

by default.

closefrom_override

If set, the user may usesudo ‘s

-C

option which overrides the default starting point at whichsudo

begins closing open file descriptors.
This flag isoff

by default.

compress_io

If set, andsudo

is configured to log a command’s input or output,
the I/O logs will be compressed usingzlib

This flag ison

by default whensudo

is compiled withzlib

support.

env_editor

If set,visudo

will use the value of theEDITOR

orVISUAL

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 theeditor

variable.visudo

will then only use theEDITOR

orVISUAL

if they match a value specified ineditor

This flag ison

by
default.

env_reset

If set,sudo

will run the command in a minimal environment containing theTERM

PATH

HOME

MAIL

SHELL

LOGNAME

USER

USERNAME

andSUDO_*

variables.
Any
variables in the caller’s environment that match theenv_keep

andenv_check

lists are then added, followed by any variables present in the file
specified by theenv_file

Set this flag if you want to put fully qualified host names in thesudoers

file when the local host name (as returned by thehostname

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 hosts 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 bysudoers

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.1xyzzy.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 onfqdn

requiressudoers

to make DNS lookups which renderssudo

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 isoff

by default.

ignore_dot

If set,sudo

will ignore "." or "" (both denoting current directory) in thePATH

environment variable; thePATH

itself is not modified.
This flag ison

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 tellssudo

how to behave when no specific LDAP entries have been matched, this
sudoOption is only meaningful for thecn=defaults

section.
This flag isoff

by default.

insults

If set,sudo

will insult users when they enter an incorrect password.
This flag isoff

by default.

log_host

If set, the host name will be logged in the (non-syslog)sudo

log file.
This flag isoff

by default.

log_input

If set,sudo

will run the command in apseudo 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 theiolog_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=

”

Theiolog_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 vialog_output

is all that is required.

log_output

If set,sudo

will run the command in apseudo tty

and log all output that is sent to the screen, similar to thescript(1)

command.
If the standard output or standard error is not connected to the
user’s tty, due to I/O redirection or because the command is part
of a pipeline, that output is also captured and stored in separate
log files.

Output is logged to the directory specified by theiolog_dir

option
Po /var/log/sudo-io

by default
Pc using a unique session ID that is included in the normal

a two-line prompt is used to make it easier
to cut and paste the challenge to a local window.
It’s not as pretty as the default but some people find it more convenient.
This flag isoff

by default.

mail_always

Send mail to themailto

user every time a users runssudo

This flag isoff

by default.

mail_badpass

Send mail to themailto

user if the user runningsudo

does not enter the correct password.
If the command the user is attempting to run is not permitted bysudoers

and one of themail_always

mail_no_host

mail_no_perms

ormail_no_user

flags are set, this flag will have no effect.
This flag isoff

by default.

mail_no_host

If set, mail will be sent to themailto

user if the invoking user exists in thesudoers

file, but is not allowed to run commands on the current host.
This flag isoff

by default.

mail_no_perms

If set, mail will be sent to themailto

user if the invoking user is allowed to usesudo

but the command they are trying is not listed in theirsudoers

file entry or is explicitly denied.
This flag isoff

by default.

mail_no_user

If set, mail will be sent to themailto

user if the invoking user is not in thesudoers

file.
This flag ison

by default.

noexec

If set, all commands run viasudo

will behave as if theNOEXEC

tag has been set, unless overridden by aEXEC

tag.
See the description ofNOEXEC and EXEC

below as well as the
Sx Preventing shell escapes

section at the end of this manual.
This flag isoff

by default.

path_info

Normally,sudo

will tell the user when a command could not be
found in theirPATH

environment variable.
Some sites may wish to disable this as it could be used to gather
information on the location of executables that the normal user does
not have access to.
The disadvantage is that if the executable is simply not in the user’sPATH

sudo

will tell the user that they are not allowed to run it, which can be confusing.
This flag ison

by default.

passprompt_override

The password prompt specified bypassprompt

will normally only be used if the password prompt provided by systems
such as PAM matches the string
“Password:”

Ifpassprompt_override

is set,passprompt

will always be used.
This flag isoff

by default.

preserve_groups

By default,sudo

will initialize the group vector to the list of groups the target user is in.
Whenpreserve_groups

is set, the user’s existing group vector is left unaltered.
The real and effective group IDs, however, are still set to match the
target user.
This flag isoff

by default.

pwfeedback

By default,sudo

reads the password like most other Unix programs,
by turning off echo until the user hits the return (or enter) key.
Some users become confused by this as it appears to them thatsudo

has hung at this point.
Whenpwfeedback

is set,sudo

will provide visual feedback when the user presses a key.
Note that this does have a security impact as an onlooker may be able to
determine the length of the password being entered.
This flag isoff

by default.

requiretty

If set,sudo

will only run when the user is logged in to a real tty.
When this flag is set,sudo

can only be run from a login session and not via other means such ascron(8)

or cgi-bin scripts.
This flag isoff

by default.

root_sudo

If set, root is allowed to runsudo

too.
Disabling this prevents users from
“chaining”

sudo

commands to get a root shell by doing something like
“sudo sudo /bin/sh

will prompt for the root password instead of the password of the invoking user.
This flag isoff

by default.

runaspw

If set,sudo

will prompt for the password of the user defined by therunas_default

option (defaults toroot

instead of the password of the invoking user.
This flag isoff

by default.

set_home

If enabled andsudo

is invoked with the
-s

option theHOME

environment variable will be set to the home directory of the target
user (which is root unless the
-u

option is used).
This effectively makes the
-s

option imply
-H

Note thatHOME

is already set when the theenv_reset

option is enabled, soset_home

is only effective for configurations where eitherenv_reset

is disabled
orHOME

is present in theenv_keep

list.
This flag isoff

by default.

set_logname

Normally,sudo

will set theLOGNAME

USER

andUSERNAME

environment variables to the name of the target user (usually root unless the
-u

option is given).
However, since some programs (including the RCS revision control system) useLOGNAME

to determine the real identity of the user, it may be desirable to
change this behavior.
This can be done by negating the set_logname option.
Note that if theenv_reset

option has not been disabled, entries in theenv_keep

list will override the value ofset_logname

This flag ison

by default.

set_utmp

When enabled,sudo

will create an entry in the utmp (or utmpx) file when a pseudo-tty
is allocated.
A pseudo-tty is allocated bysudo

when thelog_input

log_output

oruse_pty

flags are enabled.
By default, the new entry will be a copy of the user’s existing utmp
entry (if any), with the tty, time, type and pid fields updated.
This flag ison

by default.

setenv

Allow the user to disable theenv_reset

option from the command line via the
-E

option.
Additionally, environment variables set via the command line are
not subject to the restrictions imposed byenv_check

env_delete

orenv_keep

As such, only trusted users should be allowed to set variables in this manner.
This flag isoff

by default.

shell_noargs

If set andsudo

is invoked with no arguments it acts as if the
-s

option had been given.
That is, it runs a shell as root (the shell is determined by theSHELL

environment variable if it is set, falling back on the shell listed
in the invoking user’s /etc/passwd entry if not).
This flag isoff

by default.

stay_setuid

Normally, whensudo

executes a command the real and effective UIDs are set to the target
user (root by default).
This option changes that behavior such that the real UID is left
as the invoking user’s UID.
In other words, this makessudo

act as a setuid wrapper.
This can be useful on systems that disable some potentially
dangerous functionality when a program is run setuid.
This option is only effective on systems that support either thesetreuid(2)

instead of the password of the invoking user.
In addition, the time stamp file name will include the target user’s name.
Note that this flag precludes the use of a uid not listed in the passwd
database as an argument to the
-u

option.
This flag isoff

by default.

tty_tickets

If set, users must authenticate on a per-tty basis.
With this flag enabled,sudo

will use a file named for the tty the user is
logged in on in the user’s time stamp directory.
If disabled, the time stamp of the directory is used instead.
This flag ison

by default.

umask_override

If set,sudo

will set the umask as specified bysudoers

without modification.
This makes it possible to specify a more permissive umask insudoers

than the user’s own umask and matches historical behavior.
Ifumask_override

is not set,sudo

will set the umask to be the union of the user’s umask and what is specified insudoers

This flag isoff

by default.
If set,sudo

will run the command in a pseudo-pty even if no I/O logging is being gone.
A malicious program run undersudo

could conceivably fork a background process that retains to the user’s
terminal device after the main program has finished executing.
Use of this option will make that impossible.
This flag isoff

by default.

utmp_runas

If set,sudo

will store the name of the runas user when updating the utmp (or utmpx) file.
By default,sudo

stores the name of the invoking user.
This flag isoff

by default.

visiblepw

By default,sudo

will refuse to run if the user must enter a password but it is not
possible to disable echo on the terminal.
If thevisiblepw

flag is set,sudo

will prompt for a password even when it would be visible on the screen.
This makes it possible to run things like
“ssh somehost sudo ls

will close all open file descriptors other than standard input,
standard output and standard error (ie: file descriptors 0-2).
Theclosefrom

option can be used to specify a different file descriptor at which
to start closing.
The default is3

passwd_tries

The number of tries a user gets to enter his/her password beforesudo

logs the failure and exits.
The default is3

Integers that can be used in a boolean context

loglinelen

Number of characters per line for the file log.
This value is used to decide when to wrap lines for nicer log files.
This has no effect on the syslog log file, only the file log.
The default is80

(use 0 or negate the option to disable word wrap).

passwd_timeout

Number of minutes before thesudo

password prompt times out, or0

for no timeout.
The timeout may include a fractional component
if minute granularity is insufficient, for example2.5

The
default is5

timestamp_timeout

Number of minutes that can elapse beforesudo

will ask for a passwd again.
The timeout may include a fractional component if
minute granularity is insufficient, for example2.5

The default is5

Set this to0

to always prompt for a password.
If set to a value less than0

the user’s time stamp will never expire.
This can be used to allow users to create or delete their own time stamps via
“sudo -v

”

and
“sudo -k

”

respectively.

umask

Umask to use when running the command.
Negate this option or set it to 0777 to preserve the user’s umask.
The actual umask that is used will be the union of the user’s umask
and the value of theumask

option, which defaults to0022

This guarantees
thatsudo

never lowers the umask when running a command.
Note: on systems that use PAM, the default PAM configuration may specify
its own umask which will override the value set insudoers

Strings

badpass_message

Message that is displayed if a user enters an incorrect password.
The default isSorry, try again.

unless insults are enabled.

editor

A colon
(`:’

)

separated list of editors allowed to be used withvisudo

visudo

will choose the editor that matches the user’sEDITOR

environment variable if possible, or the first editor in the
list that exists and is executable.
The default is
/usr/local/bin/vi

iolog_dir

The top-level directory to use when constructing the path name for
the input/output log directory.
Only used if thelog_input

orlog_output

options are enabled or when theLOG_INPUT

orLOG_OUTPUT

tags are present for a command.
The session sequence number, if any, is stored in the directory.
The default is
/var/log/sudo-io

The following percent
(`%’

)

escape sequences are supported:

%{seq}

expanded to a monotonically increasing base-36 sequence number, such as 0100A5,
where every two digits are used to form a new directory, e.g.
01/00/A5

%{user}

expanded to the invoking user’s login name

%{group}

expanded to the name of the invoking user’s real group ID

%{runas_user}

expanded to the login name of the user the command will
be run as (e.g. root)

%{runas_group}

expanded to the group name of the user the command will
be run as (e.g. wheel)

%{hostname}

expanded to the local host name without the domain name

%{command}

expanded to the base name of the command being run

In addition, any escape sequences supported by the system’sstrftime(3)

function will be expanded.

To include a literal
`%’

character, the string
`%%’

should be used.

iolog_file

The path name, relative toiolog_dir

in which to store input/output logs when thelog_input

orlog_output

options are enabled or when theLOG_INPUT

orLOG_OUTPUT

tags are present for a command.
Note thatiolog_file

may contain directory components.
The default is
“%{seq}

”

See theiolog_dir

option above for a list of supported percent
(`%’

)

escape sequences.

In addition to the escape sequences, path names that end in six or
moreX s

will have theX s

replaced with a unique combination of digits and letters, similar to themktemp(3)

function.

mailsub

Subject of the mail sent to themailto

user.
The escape%h

will expand to the host name of the machine.
Default is
“*** SECURITY information for %h ***

”

noexec_file

This option is no longer supported.
The path to the noexec file should now be set in the
/etc/sudo.conf

file.

passprompt

The default prompt to use when asking for a password; can be overridden via the
-p

option or theSUDO_PROMPT

environment variable.
The following percent
(`%’

)

escape sequences are supported:

%H

expanded to the local host name including the domain name
(only if the machine’s host name is fully qualified or thefqdn

option is set)

%h

expanded to the local host name without the domain name

%p

expanded to the user whose password is being asked for (respects therootpw

targetpw

andrunaspw

flags insudoers

%U

expanded to the login name of the user the command will
be run as (defaults to root)

%u

expanded to the invoking user’s login name

%%

two consecutive%

characters are collapsed into a single%

character

The default value is
“[sudo] password for %p:

”

The default SELinux role to use when constructing a new security
context to run the command.
The default role may be overridden on a per-command basis insudoers

or via command line options.
This option is only available whensudo

is built with SELinux support.

runas_default

The default user to run commands as if the
-u

option is not specified on the command line.
This defaults toroot

syslog_badpri

Syslog priority to use when user authenticates unsuccessfully.
Defaults toalert

The following syslog priorities are supported:alert

crit

debug

emerg

err

info

notice

andwarning

syslog_goodpri

Syslog priority to use when user authenticates successfully.
Defaults tonotice

See
Sx syslog_badpri

for the list of supported syslog priorities.

sudoers_locale

Locale to use when parsing the sudoers file, logging commands, and
sending email.
Note that changing the locale may affect how sudoers is interpreted.
Defaults to
“C

”

timestampdir

The directory in whichsudo

stores its time stamp files.
The default is
/var/db/sudo

timestampowner

The owner of the time stamp directory and the time stamps stored therein.
The default isroot

type

The default SELinux type to use when constructing a new security
context to run the command.
The default type may be overridden on a per-command basis insudoers

or via command line options.
This option is only available whensudo

is built with SELinux support.

Strings that can be used in a boolean context

env_file

Theenv_file

option specifies the fully qualified path to a file containing variables
to be set in the environment of the program being run.
Entries in this file should either be of the form
“VARIABLE=value

”

or
“export VARIABLE=value

”

The value may optionally be surrounded by single or double quotes.
Variables in this file are subject to othersudo

environment settings such asenv_keep

andenv_check

exempt_group

Users in this group are exempt from password and PATH requirements.
The group name specified should not include a%

prefix.
This is not set by default.

group_plugin

A string containing asudoers

group plugin with optional arguments.
This can be used to implement support for thenonunix_group

syntax described earlier.
The string should consist of the plugin
path, either fully-qualified or relative to the
/usr/libexec

directory, followed by any configuration arguments the plugin requires.
These arguments (if any) will be passed to the plugin’s initialization function.
If arguments are present, the string must be enclosed in double quotes
()

For example, given
/etc/sudo-group

a group file in Unix group format, the sample group plugin can be used:

Defaults group_plugin="sample_group.so /etc/sudo-group"

For more information see
sudo_plugin5.

lecture

This option controls when a short lecture will be printed along with
the password prompt.
It has the following possible values:

always

Always lecture the user.

never

Never lecture the user.

once

Only lecture the user the first time they runsudo

If no value is specified, a value ofonce

is implied.
Negating the option results in a value ofnever

being used.
The default value isonce

lecture_file

Path to a file containing an alternatesudo

lecture that will be used in place of the standard lecture if the named
file exists.
By default,sudo

uses a built-in lecture.

listpw

This option controls when a password will be required when a user runssudo

with the
-l

option.
It has the following possible values:

all

All the user’ssudoers

entries for the current host must have
theNOPASSWD

flag set to avoid entering a password.

always

The user must always enter a password to use the
-l

option.

any

At least one of the user’ssudoers

entries for the current host
must have theNOPASSWD

flag set to avoid entering a password.

never

The user need never enter a password to use the
-l

option.

If no value is specified, a value ofany

is implied.
Negating the option results in a value ofnever

being used.
The default value isany

logfile

Path to thesudo

log file (not the syslog log file).
Setting a path turns on logging to a file;
negating this option turns it off.
By default,sudo

logs via syslog.

mailerflags

Flags to use when invoking mailer. Defaults to
-t

mailerpath

Path to mail program used to send warning mail.
Defaults to the path to sendmail found at configure time.

mailfrom

Address to use for the
“from”

address when sending warning and error mail.
The address should be enclosed in double quotes
()

to protect againstsudo

interpreting the@

sign.
Defaults to the name of the user runningsudo

mailto

Address to send warning and error mail to.
The address should be enclosed in double quotes
()

to protect againstsudo

interpreting the@

sign.
Defaults toroot

secure_path

Path used for every command run fromsudo

If you don’t trust the
people runningsudo

to have a sanePATH

environment variable you may want to use this.
Another use is if you want to have the
“root path”

be separate from the
“user path”

Users in the group specified by theexempt_group

option are not affected bysecure_path

This option is not set by default.

syslog

Syslog facility if syslog is being used for logging (negate to
disable syslog logging).
Defaults toauthpriv

The following syslog facilities are supported:authpriv

(if your
OS supports it),auth

daemon

user

local0

local1

local2

local3

local4

local5

local6

andlocal7

verifypw

This option controls when a password will be required when a user runssudo

with the
-v

option.
It has the following possible values:

all

All the user’ssudoers

entries for the current host must have theNOPASSWD

flag set to avoid entering a password.

always

The user must always enter a password to use the
-v

option.

any

At least one of the user’ssudoers

entries for the current host must have theNOPASSWD

flag set to avoid entering a password.

never

The user need never enter a password to use the
-v

option.

If no value is specified, a value ofall

is implied.
Negating the option results in a value ofnever

being used.
The default value isall

Lists that can be used in a boolean context

env_check

Environment variables to be removed from the user’s environment if
the variable’s value contains
`%’

or
`/’

characters.
This can be used to guard against printf-style format vulnerabilities
in poorly-written programs.
The argument may be a double-quoted, space-separated list or a
single value without double-quotes.
The list can be replaced, added to, deleted from, or disabled by using
the=

+=

-=

and!

operators respectively.
Regardless of whether theenv_reset

option is enabled or disabled, variables specified byenv_check

will be preserved in the environment if they pass the aforementioned check.
The default list of environment variables to check is displayed whensudo

is run by root with
the
-V

option.

env_delete

Environment variables to be removed from the user’s environment when theenv_reset

option is not in effect.
The argument may be a double-quoted, space-separated list or a
single value without double-quotes.
The list can be replaced, added to, deleted from, or disabled by using the=

+=

-=

and!

operators respectively.
The default list of environment variables to remove is displayed whensudo

is run by root with the
-V

option.
Note that many operating systems will remove potentially dangerous
variables from the environment of any setuid process (such assudo )

env_keep

Environment variables to be preserved in the user’s environment when theenv_reset

option is in effect.
This allows fine-grained control over the environmentsudo -spawned

processes will receive.
The argument may be a double-quoted, space-separated list or a
single value without double-quotes.
The list can be replaced, added to, deleted from, or disabled by using the=

+=

-=

and!

operators respectively.
The default list of variables to keep
is displayed whensudo

Each priority, when specified, also includes all priorities higher than it.
For example, a priority ofnotice

would include debug messages logged atnotice

and higher.

The following subsystems are used bysudoers

alias

User_Alias

Runas_Alias

Host_Alias

andCmnd_Alias

processing

all

matches every subsystem

audit

BSM and Linux audit code

auth

user authentication

defaults

sudoers

Defaults

settings

env

environment handling

ldap

LDAP-based sudoers

logging

logging support

match

matching of users, groups, hosts and netgroups insudoers

netif

network interface handling

nss

network service switch handling insudoers

parser

sudoers

file parsing

perms

permission setting

plugin

The equivalent ofmain

for the plugin.

pty

pseudo-tty related code

rbtree

redblack tree internals

util

utility functions

FILES

/etc/sudo.conf

Sudo front end configuration

/etc/sudoers

List of who can run what

/etc/group

Local groups file

/etc/netgroup

List of network groups

/var/log/sudo-io

I/O log files

/var/db/sudo

Directory containing time stamps for thesudoers

security policy

/etc/environment

Initial environment for
-i

mode on AIX and Linux systems

EXAMPLES

Below are examplesudoers

entries.
Admittedly, some of these are a bit contrived.
First, we allow a few environment variables to pass and then define ouraliases

# Run X applications through sudo; HOME is used to find the
# .Xauthority file. Note that other programs use HOME to find
# configuration files and this may lead to privilege escalation!
Defaults env_keep += "DISPLAY HOME"

facility in all cases.
We don’t want to subject the full time staff to thesudo

lecture, usermillert

need not give a password, and we don’t want to reset theLOGNAME

USER

orUSERNAME

environment variables when running commands as root.
Additionally, on the machines in theSERVERS

Host_Alias

we keep an additional local log file and make sure we log the year
in each log line since the log entries will be kept around for several years.
Lastly, we disable shell escapes for the commands in the PAGERSCmnd_Alias

user may run commands limited to simple maintenance.
Here, those are commands related to backups, killing processes, the
printing system, shutting down the system, and any commands in the
directory
/usr/oper/bin/

Any user may mount or unmount a CD-ROM on the machines in the CDROMHost_Alias

(orion, perseus, hercules) without entering a password.
This is a bit tedious for users to type, so it is a prime candidate
for encapsulating in a shell script.

SECURITY NOTES

Limitations of the So ! Sc operator

It is generally not effective to
“subtract”

commands fromALL

using the
`!’

operator.
A user can trivially circumvent this by copying the desired command
to a different name and then executing that.
For example:

bill ALL = ALL, !SU, !SHELLS

Doesn’t really preventbill

from running the commands listed inSU

orSHELLS

since he can simply copy those commands to a different name, or use
a shell escape from an editor or other program.
Therefore, these kind of restrictions should be considered
advisory at best (and reinforced by policy).

In general, if a user has sudoALL

there is nothing to prevent them from creating their own program that gives
them a root shell (or making their own copy of a shell) regardless of any
`!’

elements in the user specification.

Security implications of fast_glob

If thefast_glob

option is in use, it is not possible to reliably negate commands where the
path name includes globbing (aka wildcard) characters.
This is because the C library’sfnmatch(3)

function cannot resolve relative paths.
While this is typically only an inconvenience for rules that grant privileges,
it can result in a security issue for rules that subtract or revoke privileges.

Preventing shell escapes

Oncesudo

executes a program, that program is free to do whatever
it pleases, including run other programs.
This can be a security issue since it is not uncommon for a program to
allow shell escapes, which lets a user bypasssudo ‘s

access control and logging.
Common programs that permit shell escapes include shells (obviously),
editors, paginators, mail and terminal programs.

There are two basic approaches to this problem:

restrict

Avoid giving users access to commands that allow the user to run
arbitrary commands.
Many editors have a restricted mode where shell
escapes are disabled, thoughsudoedit

is a better solution to
running editors viasudo

Due to the large number of programs that
offer shell escapes, restricting users to the set of programs that
do not is often unworkable.

noexec

Many systems that support shared libraries have the ability to
override default library functions by pointing an environment
variable (usuallyLD_PRELOAD

to an alternate shared library.
On such systems,sudo ‘s

noexec

functionality can be used to prevent a program run bysudo

from executing any other programs.
Note, however, that this applies only to native dynamically-linked
executables.
Statically-linked executables and foreign executables
running under binary emulation are not affected.

Thenoexec

feature is known to work on SunOS, Solaris, *BSD,
Linux, IRIX, Tru64 UNIX, MacOS X, HP-UX 11.x and AIX 5.3 and above.
It should be supported on most operating systems that support theLD_PRELOAD

tag as documented
in the User Specification section above.
Here is that example again:

aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi

This allows useraaron

to run
/usr/bin/more

and
/usr/bin/vi

withnoexec

enabled.
This will prevent those two commands from
executing other commands (such as a shell).
If you are unsure whether or not your system is capable of supportingnoexec

you can always just try it out and check whether shell escapes work whennoexec

is enabled.

Note that restricting shell escapes is not a panacea.
Programs running as root are still capable of many potentially hazardous
operations (such as changing or overwriting files) that could lead
to unintended privilege escalation.
In the specific case of an editor, a safer approach is to give the
user permission to runsudoedit

Time stamp file checks

sudoers

will check the ownership of its time stamp directory
Po /var/db/sudo

by default
Pc and ignore the directory’s contents if it is not owned by root or

if it is writable by a user other than root.
On systems that allow non-root users to give away files viachown(2),

if the time stamp directory is located in a world-writable
directory (e.g.,
/tmp )

it is possible for a user to create the time stamp directory beforesudo

is run.
However, becausesudoers

checks the ownership and mode of the directory and its
contents, the only damage that can be done is to
“hide”

files by putting them in the time stamp dir.
This is unlikely to happen since once the time stamp dir is owned by root
and inaccessible by any other user, the user placing files there would be
unable to get them back out.

sudoers

will not honor time stamps set far in the future.
Time stamps with a date greater than current_time + 2 *TIMEOUT

will be ignored and sudo will log and complain.
This is done to keep a user from creating his/her own time stamp with a
bogus date on systems that allow users to give away files if the time
stamp directory is located in a world-writable directory.

On systems where the boot time is available,sudoers

will ignore time stamps that date from before the machine booted.

Since time stamp files live in the file system, they can outlive a
user’s login session.
As a result, a user may be able to login, run a command withsudo

after authenticating, logout, login again, and runsudo

without authenticating so long as the time stamp file’s modification
time is within5

minutes (or whatever the timeout is set to insudoers )

When thetty_tickets

option is enabled, the time stamp has per-tty granularity but still
may outlive the user’s session.
On Linux systems where the devpts filesystem is used, Solaris systems
with the devices filesystem, as well as other systems that utilize a
devfs filesystem that monotonically increase the inode number of devices
as they are created (such as Mac OS X),sudoers

is able to determine when a tty-based time stamp file is stale and will
ignore it.
Administrators should not rely on this feature as it is not universally
available.

SEE ALSO

CAVEATS

command which locks the file and does grammatical checking.
It is
imperative thatsudoers

be free of syntax errors sincesudo

will not run with a syntactically incorrectsudoers

file.

When using netgroups of machines (as opposed to users), if you
store fully qualified host name in the netgroup (as is usually the
case), you either need to have the machine’s host name be fully qualified
as returned by thehostname

SUPPORT

DISCLAIMER

sudo

is provided
“AS IS”

and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed.
See the LICENSE file distributed withsudo