sudo.man.in   [plain text]


.\" DO NOT EDIT THIS FILE, IT IS NOT THE MASTER!
.\" IT IS GENERATED AUTOMATICALLY FROM sudo.mdoc.in
.\"
.\" Copyright (c) 1994-1996, 1998-2005, 2007-2012
.\"	Todd C. Miller <Todd.Miller@courtesan.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" Sponsored in part by the Defense Advanced Research Projects
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\"
.TH "SUDO" "@mansectsu@" "July 10, 2012" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
.nh
.if n .ad l
.SH "NAME"
\fBsudo\fR,
\fBsudoedit\fR
\- execute a command as another user
.SH "SYNOPSIS"
.HP 5n
\fBsudo\fR
\fB\-h\fR | \fB\-K\fR | \fB\-k\fR | \fB\-L\fR | \fB\-V\fR
.PD 0
.HP 5n
\fBsudo\fR
\fB\-v\fR
[\fB\-AknS\fR]
[\fB\-a\fR\ \fIauth_type\fR]
[\fB\-g\fR\ \fIgroup\ name\fR\ |\ \fI#gid\fR]
[\fB\-p\fR\ \fIprompt\fR]
[\fB\-u\fR\ \fIuser\ name\fR\ |\ \fI#uid\fR]
.br
.HP 5n
\fBsudo\fR
\fB\-l\fR[\fIl\fR]
[\fB\-AknS\fR]
[\fB\-a\fR\ \fIauth_type\fR]
[\fB\-g\fR\ \fIgroup\ name\fR\ |\ \fI#gid\fR]
[\fB\-p\fR\ \fIprompt\fR]
[\fB\-U\fR\ \fIuser\ name\fR]
[\fB\-u\fR\ \fIuser\ name\fR\ |\ \fI#uid\fR]
[\fIcommand\fR]
.br
.HP 5n
\fBsudo\fR
[\fB\-AbEHnPS\fR]
[\fB\-a\fR\ \fIauth_type\fR]
[\fB\-C\fR\ \fIfd\fR]
[\fB\-c\fR\ \fIclass\fR\ |\ \fI-\fR]
[\fB\-g\fR\ \fIgroup\ name\fR\ |\ \fI#gid\fR]
[\fB\-p\fR\ \fIprompt\fR]
[\fB\-r\fR\ \fIrole\fR]
[\fB\-t\fR\ \fItype\fR]
[\fB\-u\fR\ \fIuser\ name\fR\ |\ \fI#uid\fR]
[\fBVAR\fR=\fIvalue\fR]
\fB\-i\fR\ |\ \fB\-s\fR
[\fIcommand\fR]
.br
.HP 9n
\fBsudoedit\fR
[\fB\-AnS\fR]
[\fB\-a\fR\ \fIauth_type\fR]
[\fB\-C\fR\ \fIfd\fR]
[\fB\-c\fR\ \fIclass\fR\ |\ \fI-\fR]
[\fB\-g\fR\ \fIgroup\ name\fR\ |\ \fI#gid\fR]
[\fB\-p\fR\ \fIprompt\fR]
[\fB\-u\fR\ \fIuser\ name\fR\ |\ \fI#uid\fR]
file ...
.PD
.SH "DESCRIPTION"
\fBsudo\fR
allows a permitted user to execute a
\fIcommand\fR
as the superuser or another user, as specified by the
\fIsudoers\fR
file.
See the
\fICOMMAND EXECUTION\fR
section below for more details.
.PP
\fBsudo\fR
determines who is an authorized user by consulting the file
\fI@sysconfdir@/sudoers\fR.
By running
\fBsudo\fR
with the
\fB\-v\fR
option, a user can update the time stamp without running a
\fIcommand\fR.
If authentication is required,
\fBsudo\fR
will exit if the user's password is not entered within a configurable
time limit.
The default password prompt timeout is
\fR@password_timeout@\fR
minutes.
.PP
When invoked as
\fBsudoedit\fR,
the
\fB\-e\fR
option (described below), is implied.
.PP
The options are as follows:
.TP 12n
\fB\-A\fR
Normally, if
\fBsudo\fR
requires a password, it will read it from the user's terminal.
If the
\fB\-A\fR (\fIaskpass\fR)
option is specified, a (possibly graphical) helper program is
executed to read the user's password and output the password to the
standard output.
If the
\fRSUDO_ASKPASS\fR
environment variable is set, it specifies the path to the helper
program.
Otherwise, the value specified by the
\fIaskpass\fR
option in
sudoers(@mansectform@)
is used.
If no askpass program is available,
\fBsudo\fR
will exit with an error.
.TP 12n
\fB\-a\fR \fItype\fR
The
\fB\-a\fR (\fIauthentication type\fR)
option causes
\fBsudo\fR
to use the specified authentication type when validating the user,
as allowed by
\fI/etc/login.conf\fR.
The system administrator may specify a list of sudo-specific
authentication methods by adding an
``auth-sudo''
entry in
\fI/etc/login.conf\fR.
This option is only available on systems that support BSD authentication.
.TP 12n
\fB\-b\fR
The
\fB\-b\fR (\fIbackground\fR)
option tells
\fBsudo\fR
to run the given command in the background.
Note that if you use the
\fB\-b\fR
option you cannot use shell job control to manipulate the process.
Most interactive commands will fail to work properly in background
mode.
.TP 12n
\fB\-C\fR \fIfd\fR
Normally,
\fBsudo\fR
will close all open file descriptors other than standard input,
standard output and standard error.
The
\fB\-C\fR (\fIclose from\fR)
option allows the user to specify a starting point above the standard
error (file descriptor three).
Values less than three are not permitted.
This option is only available when the administrator has enabled the
\fIclosefrom_override\fR
option in
sudoers(@mansectform@).
.TP 12n
\fB\-c\fR \fIclass\fR
The
\fB\-c\fR (\fIclass\fR)
option causes
\fBsudo\fR
to run the specified command with resources limited by the specified
login class.
The
\fIclass\fR
argument can be either a class name as defined in
\fI/etc/login.conf\fR,
or a single
`\-'
character.
Specifying a
\fIclass\fR
of
\fR-\fR
indicates that the command should be run restricted by the default
login capabilities for the user the command is run as.
If the
\fIclass\fR
argument specifies an existing user class, the command must be run
as root, or the
\fBsudo\fR
command must be run from a shell that is already root.
This option is only available on systems with BSD login classes.
.TP 12n
\fB\-E\fR
The
\fB\-E\fR (\fIpreserve environment\fR)
option will override the
\fIenv_reset\fR
option in
sudoers(@mansectform@).
It is only available when either the matching command has the
\fRSETENV\fR
tag or the
\fIsetenv\fR
option is set in
sudoers(@mansectform@).
\fBsudo\fR
will return an error if the
\fB\-E\fR
option is specified and the user does not have permission to preserve
the environment.
.TP 12n
\fB\-e\fR
The
\fB\-e\fR (\fIedit\fR)
option indicates that, instead of running a command, the user wishes
to edit one or more files.
In lieu of a command, the string "sudoedit" is used when consulting the
\fIsudoers\fR
file.
If the user is authorized by
\fIsudoers\fR,
the following steps are taken:
.RS
.TP 5n
1.
Temporary copies are made of the files to be edited with the owner
set to the invoking user.
.TP 5n
2.
The editor specified by the
\fRSUDO_EDITOR\fR,
\fRVISUAL\fR
or
\fREDITOR\fR
environment variables (in that order) is run to edit the temporary files.
If none of
\fRSUDO_EDITOR\fR,
\fRVISUAL\fR
or
\fREDITOR\fR
are set, the first program listed in the
\fIeditor\fR
sudoers(@mansectform@)
option is used.
.TP 5n
3.
If they have been modified, the temporary files are copied back to
their original location and the temporary versions are removed.
.PP
If the specified file does not exist, it will be created.
Note that unlike most commands run by
\fIsudo\fR,
the editor is run with the invoking user's environment unmodified.
If, for some reason,
\fBsudo\fR
is unable to update a file with its edited version, the user will
receive a warning and the edited copy will remain in a temporary
file.
.PP
.RE
.PD 0
.TP 12n
\fB\-g\fR \fIgroup\fR
Normally,
\fBsudo\fR
runs a command with the primary group set to the one specified by
the password database for the user the command is being run as (by
default, root).
The
\fB\-g\fR (\fIgroup\fR)
option causes
\fBsudo\fR
to run the command with the primary group set to
\fIgroup\fR
instead.
To specify a
\fIgid\fR
instead of a
\fIgroup name\fR,
use
\fI#gid\fR.
When running commands as a
\fIgid\fR,
many shells require that the
`#'
be escaped with a backslash
(`\e').
If no
\fB\-u\fR
option is specified, the command will be run as the invoking user
(not root).
In either case, the primary group will be set to
\fIgroup\fR.
.PD
.TP 12n
\fB\-H\fR
The
\fB\-H\fR (\fIHOME\fR)
option option sets the
\fRHOME\fR
environment variable to the home directory of the target user (root
by default) as specified by the password database.
The default handling of the
\fRHOME\fR
environment variable depends on
sudoers(@mansectform@)
settings.
By default,
\fBsudo\fR
will set
\fRHOME\fR
if
\fIenv_reset\fR
or
\fIalways_set_home\fR
are set, or if
\fIset_home\fR
is set and the
\fB\-s\fR
option is specified on the command line.
.TP 12n
\fB\-h\fR
The
\fB\-h\fR (\fIhelp\fR)
option causes
\fBsudo\fR
to print a short help message to the standard output and exit.
.TP 12n
\fB\-i\fR [\fIcommand\fR]
The
\fB\-i\fR (\fIsimulate initial login\fR)
option runs the shell specified by the password database entry of
the target user as a login shell.
This means that login-specific resource files such as
\fI.profile\fR
or
\fI.login\fR
will be read by the shell.
If a command is specified, it is passed to the shell for execution
via the shell's
\fB\-c\fR
option.
If no command is specified, an interactive shell is executed.
\fBsudo\fR
attempts to change to that user's home directory before running the
shell.
It also initializes the environment to a minimal
set of variables, similar to what is present when a user logs in.
The
\fICommand environment\fR
section below documents in detail how the
\fB\-i\fR
option affects the environment in which a command is run.
.TP 12n
\fB\-K\fR
The
\fB\-K\fR (sure \fIkill\fR)
option is like
\fB\-k\fR
except that it removes the user's time stamp file entirely and
may not be used in conjunction with a command or other option.
This option does not require a password.
.TP 12n
\fB\-k\fR [\fIcommand\fR]
When used alone, the
\fB\-k\fR (\fIkill\fR)
option to
\fBsudo\fR
invalidates the user's time stamp file.
The next time
\fBsudo\fR
is run a password will be required.
This option does not require a password and was added to allow a
user to revoke
\fBsudo\fR
permissions from a
\fI.logout\fR
file.
.sp
When used in conjunction with a command or an option that may require
a password, the
\fB\-k\fR
option will cause
\fBsudo\fR
to ignore the user's time stamp file.
As a result,
\fBsudo\fR
will prompt for a password (if one is required by
\fIsudoers\fR)
and will not update the user's time stamp file.
.TP 12n
\fB\-L\fR
The
\fB\-L\fR (\fIlist\fR defaults)
option will list the parameters that
may be set in a
\fIDefaults\fR
line along with a short description for each.
This option will be removed from a future version of
\fBsudo\fR.
.TP 12n
\fB\-l\fR[\fBl\fR] [\fIcommand\fR]
If no
\fIcommand\fR
is specified, the
\fB\-l\fR (\fIlist\fR)
option will list the allowed (and forbidden) commands for the
invoking user (or the user specified by the
\fB\-U\fR
option) on the current host.
If a
\fIcommand\fR
is specified and is permitted by
\fIsudoers\fR,
the fully-qualified
path to the command is displayed along with any command line
arguments.
If
\fIcommand\fR
is specified but not allowed,
\fBsudo\fR
will exit with a status value of 1.
If the
\fB\-l\fR
option is specified with an
\fIl\fR
argument
(i.e.\& \fB\-ll\fR),
or if
\fB\-l\fR
is specified multiple times, a longer list format is used.
.TP 12n
\fB\-n\fR
The
\fB\-n\fR (\fInon-interactive\fR)
option prevents
\fBsudo\fR
from prompting the user for a password.
If a password is required for the command to run,
\fBsudo\fR
will display an error message and exit.
.TP 12n
\fB\-P\fR
The
\fB\-P\fR (\fIpreserve group vector\fR)
option causes
\fBsudo\fR
to preserve the invoking user's group vector unaltered.
By default,
\fBsudo\fR
will initialize the group vector to the list of groups the
target user is in.
The real and effective group IDs, however, are still set to match
the target user.
.TP 12n
\fB\-p\fR \fIprompt\fR
The
\fB\-p\fR (\fIprompt\fR)
option allows you to override the default password prompt and use
a custom one.
The following percent
(`%')
escapes are supported:
.RS
.TP 4n
\fR%H\fR
expanded to the host name including the domain name (on if the
machine's host name is fully qualified or the
\fIfqdn\fR
option is set in
sudoers(@mansectform@))
.TP 4n
\fR%h\fR
expanded to the local host name without the domain name
.TP 4n
\fR%p\fR
expanded to the name of the user whose password is being requested
(respects the
\fIrootpw\fR,
\fItargetpw\fR,
and
\fIrunaspw\fR
flags in
sudoers(@mansectform@))
.TP 4n
\fR\&%U\fR
expanded to the login name of the user the command will be run as
(defaults to root unless the
\fB\-u\fR
option is also specified)
.TP 4n
\fR%u\fR
expanded to the invoking user's login name
.TP 4n
\fR%%\fR
two consecutive
`%'
characters are collapsed into a single
`%'
character
.PP
The prompt specified by the
\fB\-p\fR
option will override the system password prompt on systems that
support PAM unless the
\fIpassprompt_override\fR
flag is disabled in
\fIsudoers\fR.
.PP
.RE
.PD 0
.TP 12n
\fB\-r\fR \fIrole\fR
The
\fB\-r\fR (\fIrole\fR)
option causes the new (SELinux) security context to have the role
specified by
\fIrole\fR.
.PD
.TP 12n
\fB\-S\fR
The
\fB\-S\fR (\fIstdin\fR)
option causes
\fBsudo\fR
to read the password from the standard input instead of the terminal
device.
The password must be followed by a newline character.
.TP 12n
\fB\-s\fR [\fIcommand\fR]
The
\fB\-s\fR (\fIshell\fR)
option runs the shell specified by the
\fRSHELL\fR
environment variable if it is set or the shell as specified in the
password database.
If a command is specified, it is passed to the shell for execution
via the shell's
\fB\-c\fR
option.
If no command is specified, an interactive shell is executed.
.TP 12n
\fB\-t\fR \fItype\fR
The
\fB\-t\fR (\fItype\fR)
option causes the new (SELinux) security context to have the type
specified by
\fItype\fR.
If no type is specified, the default type is derived from the
specified role.
.TP 12n
\fB\-U\fR \fIuser\fR
The
\fB\-U\fR (\fIother user\fR)
option is used in conjunction with the
\fB\-l\fR
option to specify the user whose privileges should be listed.
Only root or a user with the
\fRALL\fR
privilege on the current host may use this option.
.TP 12n
\fB\-u\fR \fIuser\fR
The
\fB\-u\fR (\fIuser\fR)
option causes
\fBsudo\fR
to run the specified command as a user other than
\fIroot\fR.
To specify a
\fIuid\fR
instead of a
\fIuser name\fR,
\fI#uid\fR.
When running commands as a
\fIuid\fR,
many shells require that the
`#'
be escaped with a backslash
(`\e').
Note that if the
\fItargetpw\fR
Defaults option is set (see
sudoers(@mansectform@)),
it is not possible to run commands with a uid not listed in the
password database.
.TP 12n
\fB\-V\fR
The
\fB\-V\fR (\fIversion\fR)
option causes
\fBsudo\fR
to print its version string and exit.
If the invoking user is already root the
\fB\-V\fR
option will display the arguments passed to configure when
\fBsudo\fR
was built as well a list of the defaults
\fBsudo\fR
was compiled with as well as the machine's local network addresses.
.TP 12n
\fB\-v\fR
When given the
\fB\-v\fR (\fIvalidate\fR)
option,
\fBsudo\fR
will update the user's time stamp file, authenticating the user's
password if necessary.
This extends the
\fBsudo\fR
timeout for another
\fR@timeout@\fR
minutes (or whatever the timeout is set to in
\fIsudoers\fR)
but does not run a command.
.TP 12n
\fB\--\fR
The
\fB\--\fR
option indicates that
\fBsudo\fR
should stop processing command line arguments.
.PP
Environment variables to be set for the command may also be passed
on the command line in the form of
\fBVAR\fR=\fIvalue\fR,
e.g.\&
\fBLD_LIBRARY_PATH\fR=\fI/usr/local/pkg/lib\fR.
Variables passed on the command line are subject to the same
restrictions as normal environment variables with one important
exception.
If the
\fIsetenv\fR
option is set in
\fIsudoers\fR,
the command to be run has the
\fRSETENV\fR
tag set or the command matched is
\fRALL\fR,
the user may set variables that would otherwise be forbidden.
See
sudoers(@mansectform@)
for more information.
.SS "Authentication and logging"
\fBsudo\fR
requires that most users authenticate themselves by default.
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 authentication has been disabled for the
user or command in the
\fIsudoers\fR
file.
Unlike
su(1),
when
\fBsudo\fR
requires
authentication, it validates the invoking user's credentials, not
the target user's (or root's) credentials.
This can be changed via
the
\fIrootpw\fR,
\fItargetpw\fR
and
\fIrunaspw\fR
Defaults entries in
\fIsudoers\fR.
.PP
If a user who is not listed in
\fIsudoers\fR
tries to run a command via
\fBsudo\fR,
mail is sent to the proper authorities.
The address
used for such mail is configurable via the
\fImailto\fR
\fIsudoers\fR
Defaults entry and defaults to
\fR@mailto@\fR.
.PP
Note that mail will not be sent if an unauthorized user tries to
run
\fBsudo\fR
with the
\fB\-l\fR
or
\fB\-v\fR
option.
This allows users to
determine for themselves whether or not they are allowed to use
\fBsudo\fR.
.PP
If
\fBsudo\fR
is run by root and the
\fRSUDO_USER\fR
environment variable
is set, its value will be used to determine who the actual user is.
This can be used by a user to log commands
through
\fBsudo\fR
even when a root shell has been invoked.
It also
allows the
\fB\-e\fR
option to remain useful even when invoked via a
sudo-run script or program.
Note, however, that the
\fIsudoers\fR
lookup is still done for root, not the user specified by
\fRSUDO_USER\fR.
.PP
\fBsudo\fR
uses time stamp files for credential caching.
Once a
user has been authenticated, the time stamp is updated and the user
may then use sudo without a password for a short period of time
(\fR@timeout@\fR
minutes unless overridden by the
\fItimeout\fR
option)
\&.
By default,
\fBsudo\fR
uses a tty-based time stamp which means that
there is a separate time stamp for each of a user's login sessions.
The
\fItty_tickets\fR
option can be disabled to force the use of a
single time stamp for all of a user's sessions.
.PP
\fBsudo\fR
can log both successful and unsuccessful attempts (as well
as errors) to
syslog(3),
a log file, or both.
By default,
\fBsudo\fR
will log via
syslog(3)
but this is changeable via the
\fIsyslog\fR
and
\fIlogfile\fR
Defaults settings.
.PP
\fBsudo\fR
also supports logging a command's input and output
streams.
I/O logging is not on by default but can be enabled using
the
\fIlog_input\fR
and
\fIlog_output\fR
Defaults flags as well as the
\fRLOG_INPUT\fR
and
\fRLOG_OUTPUT\fR
command tags.
.SS "Command environment"
Since environment variables can influence program behavior,
\fBsudo\fR
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
\fIsudoers\fR
can be configured to handle with environment variables.
.PP
By default, the
\fIenv_reset\fR
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
\fI/etc/environment\fR
file.
On BSD systems, if the
\fIuse_loginclass\fR
option is enabled, the environment is initialized
based on the
\fIpath\fR
and
\fIsetenv\fR
settings in
\fI/etc/login.conf\fR.
The new environment contains the
\fRTERM\fR,
\fRPATH\fR,
\fRHOME\fR,
\fRMAIL\fR,
\fRSHELL\fR,
\fRLOGNAME\fR,
\fRUSER\fR,
\fRUSERNAME\fR
and
\fRSUDO_*\fR
variables
in addition to variables from the invoking process permitted by the
\fIenv_check\fR
and
\fIenv_keep\fR
options.
This is effectively a whitelist
for environment variables.
.PP
If, however, the
\fIenv_reset\fR
option is disabled, any variables not
explicitly denied by the
\fIenv_check\fR
and
\fIenv_delete\fR
options are
inherited from the invoking process.
In this case,
\fIenv_check\fR
and
\fIenv_delete\fR
behave like a blacklist.
Since it is not possible
to blacklist all potentially dangerous environment variables, use
of the default
\fIenv_reset\fR
behavior is encouraged.
.PP
In all cases, environment variables with a value beginning with
\fR()\fR
are removed as they could be interpreted as
\fBbash\fR
functions.
The list of environment variables that
\fBsudo\fR
allows or denies is
contained in the output of
``\fRsudo -V\fR''
when run as root.
On Mac OS X, \fIsudoers\fR has been configured to only whitelist a small set
of environment variables by default.  See the \fIsudoers\fR file for more
information.
.PP
Note that the dynamic linker on most operating systems will remove
variables that can control dynamic linking from the environment of
setuid executables, including
\fBsudo\fR.
Depending on the operating
system this may include
\fR_RLD*\fR,
\fRDYLD_*\fR,
\fRLD_*\fR,
\fRLDR_*\fR,
\fRLIBPATH\fR,
\fRSHLIB_PATH\fR,
and others.
These type of variables are
removed from the environment before
\fBsudo\fR
even begins execution
and, as such, it is not possible for
\fBsudo\fR
to preserve them.
.PP
As a special case, if
\fBsudo\fR's
\fB\-i\fR
option (initial login) is
specified,
\fBsudo\fR
will initialize the environment regardless
of the value of
\fIenv_reset\fR.
The
\fRDISPLAY\fR,
\fRPATH\fR
and
\fRTERM\fR
variables remain unchanged;
\fRHOME\fR,
\fRMAIL\fR,
\fRSHELL\fR,
\fRUSER\fR,
and
\fRLOGNAME\fR
are set based on the target user.
On AIX (and Linux
systems without PAM), the contents of
\fI/etc/environment\fR
are also
included.
On BSD systems, if the
\fIuse_loginclass\fR
option is
enabled, the
\fIpath\fR
and
\fIsetenv\fR
variables in
\fI/etc/login.conf\fR
are also applied.
All other environment variables are removed.
.PP
Finally, if the
\fIenv_file\fR
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.
.SH "COMMAND EXECUTION"
When
\fBsudo\fR
executes a command, the
\fIsudoers\fR
file specifies the execution envionment for the command.
Typically, the real and effective uid and gid are set to
match those of the target user, as specified in the password database,
and the group vector is initialized based on the group database
(unless the
\fB\-P\fR
option was specified).
.PP
The
\fIsudoers\fR
file settings affect the following execution parameters:
.TP 4n
\fBo\fR
real and effective user ID
.TP 4n
\fBo\fR
real and effective group ID
.TP 4n
\fBo\fR
supplementary group IDs
.TP 4n
\fBo\fR
the environment list
.TP 4n
\fBo\fR
SELinux role and type
.TP 4n
\fBo\fR
Solaris project
.TP 4n
\fBo\fR
Solaris privileges
.TP 4n
\fBo\fR
BSD login class
.TP 4n
\fBo\fR
file creation mode mask (umask)
.PP
See the
\fICommand environment\fR
section for details on how the environment list is constructed.
.SS "Process model"
If
\fBsudo\fR
has been configured with PAM support or if I/O logging is enabled,
\fBsudo\fR
must wait until the command has completed before it will exit.
In the case of PAM,
\fBsudo\fR
must remain running so that it can close the PAM session
when the command is finished.
If neither PAM nor I/O logging are configured,
\fBsudo\fR
will execute the command without calling
fork(2).
In either case,
\fBsudo\fR
sets up the execution environment as described above, and calls the
execve
system call (potentially in a child process).
If I/O logging is enabled, a new pseudo-terminal
(``pty'')
is created and a second
\fBsudo\fR
process is used to relay job control signals between the user's
existing pty and the new pty the command is being run in.
This extra process makes it possible to, for example, suspend
and resume the command.
Without it, the command would be in what POSIX terms an
``orphaned process group''
and it would not receive any job control signals.
.SS "Signal handling"
If the command is run as a child of the
\fBsudo\fR
process (due to PAM or I/O logging),
\fBsudo\fR
will relay signals it receives to the command.
Unless the command is being run in a new pty, the
\fRSIGHUP\fR,
\fRSIGINT\fR
and
\fRSIGQUIT\fR
signals are not relayed unless they are sent by a user process,
not the kernel.
Otherwise, the command would receive
\fRSIGINT\fR
twice every time the user entered control-C.
Some signals, such as
\fRSIGSTOP\fR
and
\fRSIGKILL\fR,
cannot be caught and thus will not be relayed to the command.
As a general rule,
\fRSIGTSTP\fR
should be used instead of
\fRSIGSTOP\fR
when you wish to suspend a command being run by
\fBsudo\fR.
.PP
As a special case,
\fBsudo\fR
will not relay signals that were sent by the command it is running.
This prevents the command from accidentally killing itself.
On some systems, the
reboot(@mansectsu@)
command sends
\fRSIGTERM\fR
to all non-system processes other than itself before rebooting
the systyem.
This prevents
\fBsudo\fR
from relaying the
\fRSIGTERM\fR
signal it received back to
reboot(@mansectsu@),
which might then exit before the system was actually rebooted,
leaving it in a half-dead state similar to single user mode.
Note, however, that this check only applies to the command run by
\fBsudo\fR
and not any other processes that the command may create.
As a result, running a script that calls
reboot(@mansectsu@)
or
shutdown(@mansectsu@)
via
\fBsudo\fR
may cause the system to end up in this undefined state unless the
reboot(@mansectsu@)
or
shutdown(@mansectsu@)
are run using the
\fBexec\fR()
family of functions instead of
\fBsystem\fR()
(which interposes a shell between the command and the calling process).
.SH "EXIT VALUE"
Upon successful execution of a program, the exit status from
\fIsudo\fR
will simply be the exit status of the program that was executed.
.PP
Otherwise,
\fBsudo\fR
exits with a value of 1 if there is a configuration/permission
problem or if
\fBsudo\fR
cannot execute the given command.
In the latter case the error string is printed to the standard error.
If
\fBsudo\fR
cannot
stat(2)
one or more entries in the user's
\fRPATH\fR,
an error is printed on stderr.
(If the directory does not exist or if it is not really a directory,
the entry is ignored and no error is printed.)
This should not happen under normal circumstances.
The most common reason for
stat(2)
to return
``permission denied''
is if you are running an automounter and one of the directories in
your
\fRPATH\fR
is on a machine that is currently unreachable.
.SH "LOG FORMAT"
\fBsudo\fR
can log events using either
syslog(3)
or a simple log file.
In each case the log format is almost identical.
.SS "Accepted command log entries"
Commands that sudo runs are logged using the following format (split
into multiple lines for readability):
.nf
.sp
.RS 4n
date hostname progname: username : TTY=ttyname ; PWD=cwd ; \e
    USER=runasuser ; GROUP=runasgroup ; TSID=logid ; \e
    ENV=env_vars COMMAND=command
.RE
.fi
.PP
Where the fields are as follows:
.TP 14n
date
The date the command was run.
Typically, this is in the format
``MMM, DD, HH:MM:SS''.
If logging via
syslog(3),
the actual date format is controlled by the syslog daemon.
If logging to a file and the
\fIlog_year\fR
option is enabled,
the date will also include the year.
.TP 14n
hostname
The name of the host
\fBsudo\fR
was run on.
This field is only present when logging via
syslog(3).
.TP 14n
progname
The name of the program, usually
\fIsudo\fR
or
\fIsudoedit\fR.
This field is only present when logging via
syslog(3).
.TP 14n
username
The login name of the user who ran
\fBsudo\fR.
.TP 14n
ttyname
The short name of the terminal (e.g.\&
``console'',
``tty01'',
or
``pts/0'')
\fBsudo\fR
was run on, or
``unknown''
if there was no terminal present.
.TP 14n
cwd
The current working directory that
\fBsudo\fR
was run in.
.TP 14n
runasuser
The user the command was run as.
.TP 14n
runasgroup
The group the command was run as if one was specified on the command line.
.TP 14n
logid
An I/O log identifier that can be used to replay the command's output.
This is only present when the
\fIlog_input\fR
or
\fIlog_output\fR
option is enabled.
.TP 14n
env_vars
A list of environment variables specified on the command line,
if specified.
.TP 14n
command
The actual command that was executed.
.PP
Messages are logged using the locale specified by
\fIsudoers_locale\fR,
which defaults to the
``\fRC\fR''
locale.
.SS "Denied command log entries"
If the user is not allowed to run the command, the reason for the denial
will follow the user name.
Possible reasons include:
.TP 3n
user NOT in sudoers
The user is not listed in the
\fIsudoers\fR
file.
.TP 3n
user NOT authorized on host
The user is listed in the
\fIsudoers\fR
file but is not allowed to run commands on the host.
.TP 3n
command not allowed
The user is listed in the
\fIsudoers\fR
file for the host but they are not allowed to run the specified command.
.TP 3n
3 incorrect password attempts
The user failed to enter their password after 3 tries.
The actual number of tries will vary based on the number of
failed attempts and the value of the
\fIpasswd_tries\fR
\fIsudoers\fR
option.
.TP 3n
a password is required
The
\fB\-n\fR
option was specified but a password was required.
.TP 3n
sorry, you are not allowed to set the following environment variables
The user specified environment variables on the command line that
were not allowed by
\fIsudoers\fR.
.SS "Error log entries"
If an error occurs,
\fBsudo\fR
will log a message and, in most cases, send a message to the
administrator via email.
Possible errors include:
.TP 3n
parse error in @sysconfdir@/sudoers near line N
\fBsudo\fR
encountered an error when parsing the specified file.
In some cases, the actual error may be one line above or below the
line number listed, depending on the type of error.
.TP 3n
problem with defaults entries
The
\fIsudoers\fR
file contains one or more unknown Defaults settings.
This does not prevent
\fBsudo\fR
from running, but the
\fIsudoers\fR
file should be checked using
\fBvisudo\fR.
.TP 3n
timestamp owner (username): \&No such user
The time stamp directory owner, as specified by the
\fItimestampowner\fR
setting, could not be found in the password database.
.TP 3n
unable to open/read @sysconfdir@/sudoers
The
\fIsudoers\fR
file could not be opened for reading.
This can happen when the
\fIsudoers\fR
file is located on a remote file system that maps user ID 0 to
a different value.
Normally,
\fBsudo\fR
tries to open
\fIsudoers\fR
using group permissions to avoid this problem.
.TP 3n
unable to stat @sysconfdir@/sudoers
The
\fI@sysconfdir@/sudoers\fR
file is missing.
.TP 3n
@sysconfdir@/sudoers is not a regular file
The
\fI@sysconfdir@/sudoers\fR
file exists but is not a regular file or symbolic link.
.TP 3n
@sysconfdir@/sudoers is owned by uid N, should be 0
The
\fIsudoers\fR
file has the wrong owner.
.TP 3n
@sysconfdir@/sudoers is world writable
The permissions on the
\fIsudoers\fR
file allow all users to write to it.
The
\fIsudoers\fR
file must not be world-writable, the default file mode
is 0440 (readable by owner and group, writable by none).
.TP 3n
@sysconfdir@/sudoers is owned by gid N, should be 1
The
\fIsudoers\fR
file has the wrong group ownership.
.TP 3n
unable to open @timedir@/username/ttyname
\fIsudoers\fR
was unable to read or create the user's time stamp file.
.TP 3n
unable to write to @timedir@/username/ttyname
\fIsudoers\fR
was unable to write to the user's time stamp file.
.TP 3n
unable to mkdir to @timedir@/username
\fIsudoers\fR
was unable to create the user's time stamp directory.
.SS "Notes on logging via syslog"
By default,
\fIsudoers\fR
logs messages via
syslog(3).
The
\fIdate\fR,
\fIhostname\fR,
and
\fIprogname\fR
fields are added by the syslog daemon, not
\fIsudoers\fR
itself.
As such, they may vary in format on different systems.
.PP
On most systems,
syslog(3)
has a relatively small log buffer.
To prevent the command line arguments from being truncated,
\fBsudo\fR
will split up log messages that are larger than 960 characters
(not including the date, hostname, and the string
``sudo'').
When a message is split, additional parts will include the string
``(command continued)''
after the user name and before the continued command line arguments.
.SS "Notes on logging to a file"
If the
\fIlogfile\fR
option is set,
\fIsudoers\fR
will log to a local file, such as
\fI/var/log/sudo\fR.
When logging to a file,
\fIsudoers\fR
uses a format similar to
syslog(3),
with a few important differences:
.TP 5n
1.
The
\fIprogname\fR
and
\fIhostname\fR
fields are not present.
.TP 5n
2.
If the
\fIlog_year\fR
\fIsudoers\fR
option is enabled,
the date will also include the year.
.TP 5n
3.
Lines that are longer than
\fIloglinelen\fR
characters (80 by default) are word-wrapped and continued on the
next line with a four character indent.
This makes entries easier to read for a human being, but makes it
more difficult to use
grep(1)
on the log files.
If the
\fIloglinelen\fR
\fIsudoers\fR
option is set to 0 (or negated with a
`\&!'),
word wrap will be disabled.
.SH "SECURITY NOTES"
\fBsudo\fR
tries to be safe when executing external commands.
.PP
To prevent command spoofing,
\fBsudo\fR
checks "." and "" (both denoting current directory) last when
searching for a command in the user's
\fRPATH\fR
(if one or both are in the
\fRPATH\fR).
Note, however, that the actual
\fRPATH\fR
environment variable is
\fInot\fR
modified and is passed unchanged to the program that
\fBsudo\fR
executes.
.PP
\fBsudo\fR
will check the ownership of its time stamp directory
(\fI@timedir@\fR
by default)
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 via
chown(2),
if the time stamp directory is located in a world-writable
directory (e.g.\&,
\fI/tmp\fR),
it is possible for a user to create the time stamp directory before
\fBsudo\fR
is run.
However, because
\fBsudo\fR
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.
.PP
\fBsudo\fR
will not honor time stamps set far in the future.
Time stamps with a date greater than current_time + 2 *
\fRTIMEOUT\fR
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.
.PP
On systems where the boot time is available,
\fBsudo\fR
will ignore time stamps that date from before the machine booted.
.PP
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 with
\fBsudo\fR
after authenticating, logout, login again, and run
\fBsudo\fR
without authenticating so long as the time stamp file's modification
time is within
\fR@timeout@\fR
minutes (or whatever the timeout is set to in
\fIsudoers\fR).
When the
\fItty_tickets\fR
\fIsudoers\fR
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),
\fBsudo\fR
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.
.PP
Please note that
\fBsudo\fR
will normally only log the command it explicitly runs.
If a user runs a command such as
\fRsudo su\fR
or
\fRsudo sh\fR,
subsequent commands run from that shell are not subject to
\fBsudo\fR's
security policy.
The same is true for commands that offer shell escapes (including
most editors).
If I/O logging is enabled, subsequent commands will have their input and/or
output logged, but there will not be traditional logs for those commands.
Because of this, care must be taken when giving users access to commands via
\fBsudo\fR
to verify that the command does not inadvertently give the user an
effective root shell.
For more information, please see the
\fIPREVENTING SHELL ESCAPES\fR
section in
sudoers(@mansectform@).
.PP
To prevent the disclosure of potentially sensitive information,
\fBsudo\fR
disables core dumps by default while it is executing (they are
re-enabled for the command that is run).
.PP
For information on the security implications of
\fIsudoers\fR
entries, please see the
\fISECURITY NOTES\fR
section in
sudoers(@mansectform@).
.SH "ENVIRONMENT"
\fBsudo\fR
utilizes the following environment variables:
.TP 17n
\fREDITOR\fR
Default editor to use in
\fB\-e\fR
(sudoedit) mode if neither
\fRSUDO_EDITOR\fR
nor
\fRVISUAL\fR
is set.
.TP 17n
\fRMAIL\fR
In
\fB\-i\fR
mode or when
\fIenv_reset\fR
is enabled in
\fIsudoers\fR,
set to the mail spool of the target user.
.TP 17n
\fRHOME\fR
Set to the home directory of the target user if
\fB\-i\fR
or
\fB\-H\fR
are specified,
\fIenv_reset\fR
or
\fIalways_set_home\fR
are set in
\fIsudoers\fR,
or when the
\fB\-s\fR
option is specified and
\fIset_home\fR
is set in
\fIsudoers\fR.
.TP 17n
\fRPATH\fR
Set to a sane value if the
\fIsecure_path\fR
option is set in the
\fIsudoers\fR
file.
.TP 17n
\fRSHELL\fR
Used to determine shell to run with
\fB\-s\fR
option.
.TP 17n
\fRSUDO_ASKPASS\fR
Specifies the path to a helper program used to read the password
if no terminal is available or if the
\fB\-A\fR
option is specified.
.TP 17n
\fRSUDO_COMMAND\fR
Set to the command run by sudo.
.TP 17n
\fRSUDO_EDITOR\fR
Default editor to use in
\fB\-e\fR
(sudoedit) mode.
.TP 17n
\fRSUDO_GID\fR
Set to the group ID of the user who invoked sudo.
.TP 17n
\fRSUDO_PROMPT\fR
Used as the default password prompt.
.TP 17n
\fRSUDO_PS1\fR
If set,
\fRPS1\fR
will be set to its value for the program being run.
.TP 17n
\fRSUDO_UID\fR
Set to the user ID of the user who invoked sudo.
.TP 17n
\fRSUDO_USER\fR
Set to the login name of the user who invoked sudo.
.TP 17n
\fRUSER\fR
Set to the target user (root unless the
\fB\-u\fR
option is specified).
.TP 17n
\fRVISUAL\fR
Default editor to use in
\fB\-e\fR
(sudoedit) mode if
\fRSUDO_EDITOR\fR
is not set.
.SH "FILES"
.TP 26n
\fI@sysconfdir@/sudoers\fR
List of who can run what
.TP 26n
\fI@timedir@\fR
Directory containing time stamps
.TP 26n
\fI/etc/environment\fR
Initial environment for
\fB\-i\fR
mode on AIX and Linux systems
.SH "EXAMPLES"
Note: the following examples assume suitable
sudoers(@mansectform@)
entries.
.PP
To get a file listing of an unreadable directory:
.nf
.sp
.RS 6n
$ sudo ls /usr/local/protected
.RE
.fi
.PP
To list the home directory of user yaz on a machine where the file
system holding ~yaz is not exported as root:
.nf
.sp
.RS 6n
$ sudo -u yaz ls ~yaz
.RE
.fi
.PP
To edit the
\fIindex.html\fR
file as user www:
.nf
.sp
.RS 6n
$ sudo -u www vi ~www/htdocs/index.html
.RE
.fi
.PP
To view system logs only accessible to root and users in the adm
group:
.nf
.sp
.RS 6n
$ sudo -g adm view /var/log/syslog
.RE
.fi
.PP
To run an editor as jim with a different primary group:
.nf
.sp
.RS 6n
$ sudo -u jim -g audio vi ~jim/sound.txt
.RE
.fi
.PP
To shut down a machine:
.nf
.sp
.RS 6n
$ sudo shutdown -r +15 "quick reboot"
.RE
.fi
.PP
To make a usage listing of the directories in the /home partition.
Note that this runs the commands in a sub-shell to make the
\fRcd\fR
and file redirection work.
.nf
.sp
.RS 6n
$ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
.RE
.fi
.SH "SEE ALSO"
grep(1),
su(1),
stat(2),
login_cap(3),
passwd(@mansectform@),
sudoers(@mansectform@),
sudoreplay(@mansectsu@),
visudo(@mansectsu@)
.SH "HISTORY"
See the HISTORY file in the
\fBsudo\fR
distribution (http://www.sudo.ws/sudo/history.html) for a brief
history of sudo.
.SH "AUTHORS"
Many people have worked on
\fBsudo\fR
over the years; this version consists of code written primarily by:
.sp
.RS 6n
Todd C. Miller
.RE
.PP
See the CONTRIBUTORS file in the
\fBsudo\fR
distribution (http://www.sudo.ws/sudo/contributors.html) for an
exhaustive list of people who have contributed to
\fBsudo\fR.
.SH "CAVEATS"
There is no easy way to prevent a user from gaining a root shell
if that user is allowed to run arbitrary commands via
\fBsudo\fR.
Also, many programs (such as editors) allow the user to run commands
via shell escapes, thus avoiding
\fBsudo\fR's
checks.
However, on most systems it is possible to prevent shell escapes with
\fBsudo ' s\fR
\fInoexec\fR
functionality.
See the
sudoers(@mansectform@)
manual for details.
.PP
It is not meaningful to run the
\fRcd\fR
command directly via sudo, e.g.,
.nf
.sp
.RS 6n
$ sudo cd /usr/local/protected
.RE
.fi
.PP
since when the command exits the parent process (your shell) will
still be the same.
Please see the
\fIEXAMPLES\fR
section for more information.
.PP
Running shell scripts via
\fBsudo\fR
can expose the same kernel bugs that make setuid shell scripts
unsafe on some operating systems (if your OS has a /dev/fd/ directory,
setuid shell scripts are generally safe).
.SH "BUGS"
If you feel you have found a bug in
\fBsudo\fR,
please submit a bug report at http://www.sudo.ws/sudo/bugs/
.SH "SUPPORT"
Limited free support is available via the sudo-users mailing list,
see http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or
search the archives.
.SH "DISCLAIMER"
\fBsudo\fR
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 with
\fBsudo\fR
or http://www.sudo.ws/sudo/license.html for complete details.