Imported Upstream version 1.6.6
[debian/sudo] / sudo.pod
1 =cut
2 Copyright (c) 1994-1996,1998-2002 Todd C. Miller <Todd.Miller@courtesan.com>
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 1. Redistributions of source code must retain the above copyright
10    notice, this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
15
16 3. The name of the author may not be used to endorse or promote products
17    derived from this software without specific prior written permission
18    from the author.
19
20 4. Products derived from this software may not be called "Sudo" nor
21    may "Sudo" appear in their names without specific prior written
22    permission from the author.
23
24 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
27 THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35 $Sudo: sudo.pod,v 1.51 2002/01/12 22:55:01 millert Exp $
36 =pod
37
38 =head1 NAME
39
40 sudo - execute a command as another user
41
42 =head1 SYNOPSIS
43
44 B<sudo> B<-V> | B<-h> | B<-l> | B<-L> | B<-v> | B<-k> | B<-K> | B<-s> |
45 [ B<-H> ] [B<-P> ] [B<-S> ] [ B<-b> ] | [ B<-p> I<prompt> ]
46 [ B<-c> I<class>|I<-> ] [ B<-a> I<auth_type> ]
47 [ B<-u> I<username>|I<#uid> ] I<command>
48
49 =head1 DESCRIPTION
50
51 B<sudo> allows a permitted user to execute a I<command> as the
52 superuser or another user, as specified in the I<sudoers> file.
53 The real and effective uid and gid are set to match those of the
54 target user as specified in the passwd file (the group vector is
55 also initialized when the target user is not root).  By default,
56 B<sudo> requires that users authenticate themselves with a password
57 (NOTE: by default this is the user's password, not the root password).
58 Once a user has been authenticated, a timestamp is updated and the
59 user may then use sudo without a password for a short period of
60 time (C<@timeout@> minutes unless overridden in I<sudoers>).
61
62 B<sudo> determines who is an authorized user by consulting the file
63 F<@sysconfdir@/sudoers>.  By giving B<sudo> the B<-v> flag a user
64 can update the time stamp without running a I<command.> The password
65 prompt itself will also time out if the user's password is not
66 entered within C<@password_timeout@> minutes (unless overridden via
67 I<sudoers>).
68
69 If a user who is not listed in the I<sudoers> file tries to run a
70 command via B<sudo>, mail is sent to the proper authorities, as
71 defined at configure time or the I<sudoers> file (defaults to root).
72 Note that the mail will not be sent if an unauthorized user tries
73 to run sudo with the B<-l> or B<-v> flags.  This allows users to
74 determine for themselves whether or not they are allowed to use
75 B<sudo>.
76
77 B<sudo> can log both successful and unsuccessful attempts (as well
78 as errors) to syslog(3), a log file, or both.  By default B<sudo>
79 will log via syslog(3) but this is changeable at configure time
80 or via the I<sudoers> file.
81
82 =head1 OPTIONS
83
84 B<sudo> accepts the following command line options:
85
86 =over 4
87
88 =item -V
89
90 The B<-V> (I<version>) option causes B<sudo> to print the
91 version number and exit.  If the invoking user is already root
92 the B<-V> option will print out a list of the defaults B<sudo>
93 was compiled with as well as the machine's local network addresses.
94
95 =item -l
96
97 The B<-l> (I<list>) option will list out the allowed (and
98 forbidden) commands for the user on the current host.
99
100 =item -L
101
102 The B<-L> (I<list> defaults) option will list out the parameters
103 that may be set in a I<Defaults> line along with a short description
104 for each.  This option is useful in conjunction with grep(1).
105
106 =item -h
107
108 The B<-h> (I<help>) option causes B<sudo> to print a usage message and exit.
109
110 =item -v
111
112 If given the B<-v> (I<validate>) option, B<sudo> will update the
113 user's timestamp, prompting for the user's password if necessary.
114 This extends the B<sudo> timeout for another C<@timeout@> minutes
115 (or whatever the timeout is set to in I<sudoers>) but does not run
116 a command.
117
118 =item -k
119
120 The B<-k> (I<kill>) option to B<sudo> invalidates the user's timestamp
121 by setting the time on it to the epoch.  The next time B<sudo> is
122 run a password will be required.  This option does not require a password
123 and was added to allow a user to revoke B<sudo> permissions from a .logout
124 file.
125
126 =item -K
127
128 The B<-K> (sure I<kill>) option to B<sudo> removes the user's timestamp
129 entirely.  Likewise, this option does not require a password.
130
131 =item -b
132
133 The B<-b> (I<background>) option tells B<sudo> to run the given
134 command in the background.  Note that if you use the B<-b>
135 option you cannot use shell job control to manipulate the process.
136
137 =item -p
138
139 The B<-p> (I<prompt>) option allows you to override the default
140 password prompt and use a custom one.  If the password prompt
141 contains the C<%u> escape, C<%u> will be replaced with the user's
142 login name.  Similarly, C<%h> will be replaced with the local
143 hostname.
144
145 =item -c
146
147 The B<-c> (I<class>) option causes B<sudo> to run the specified command
148 with resources limited by the specified login class.  The I<class>
149 argument can be either a class name as defined in /etc/login.conf,
150 or a single '-' character.  Specifying a I<class> of C<-> indicates
151 that the command should be run restricted by the default login
152 capabilities for the user the command is run as.  If the I<class>
153 argument specifies an existing user class, the command must be run
154 as root, or the B<sudo> command must be run from a shell that is already
155 root.  This option is only available on systems with BSD login classes
156 where B<sudo> has been configured with the --with-logincap option.
157
158 =item -a
159
160 The B<-a> (I<authentication type>) option causes B<sudo> to use the
161 specified authentication type when validating the user, as allowed
162 by /etc/login.conf.  The system administrator may specify a list
163 of sudo-specific authentication methods by adding an "auth-sudo"
164 entry in /etc/login.conf.  This option is only available on systems
165 that support BSD authentication where B<sudo> has been configured
166 with the --with-bsdauth option.
167
168 =item -u
169
170 The B<-u> (I<user>) option causes B<sudo> to run the specified command
171 as a user other than I<root>.  To specify a I<uid> instead of a
172 I<username>, use I<#uid>.
173
174 =item -s
175
176 The B<-s> (I<shell>) option runs the shell specified by the I<SHELL>
177 environment variable if it is set or the shell as specified
178 in passwd(5).
179
180 =item -H
181
182 The B<-H> (I<HOME>) option sets the C<HOME> environment variable
183 to the homedir of the target user (root by default) as specified
184 in passwd(5).  By default, B<sudo> does not modify C<HOME>.
185
186 =item -P
187
188 The B<-P> (I<preserve group vector>) option causes B<sudo> to preserve
189 the user's group vector unaltered.  By default, B<sudo> will initialize
190 the group vector to the list of groups the target user is in.
191 The real and effective group IDs, however, are still set to match
192 the target user.
193
194 =item -S
195
196 The B<-S> (I<stdin>) option causes B<sudo> to read the password from
197 standard input instead of the terminal device.
198
199 =item --
200
201 The B<--> flag indicates that B<sudo> should stop processing command
202 line arguments.  It is most useful in conjunction with the B<-s> flag.
203
204 =back
205
206 =head1 RETURN VALUES
207
208 Upon successful execution of a program, the return value from B<sudo>
209 will simply be the return value of the program that was executed.
210
211 Otherwise, B<sudo> quits with an exit value of 1 if there is a
212 configuration/permission problem or if B<sudo> cannot execute the
213 given command.  In the latter case the error string is printed to
214 stderr.  If B<sudo> cannot stat(2) one or more entries in the user's
215 C<PATH> an error is printed on stderr.  (If the directory does not
216 exist or if it is not really a directory, the entry is ignored and
217 no error is printed.)  This should not happen under normal
218 circumstances.  The most common reason for stat(2) to return
219 "permission denied" is if you are running an automounter and one
220 of the directories in your C<PATH> is on a machine that is currently
221 unreachable.
222
223 =head1 SECURITY NOTES
224
225 B<sudo> tries to be safe when executing external commands.  Variables
226 that control how dynamic loading and binding is done can be used
227 to subvert the program that B<sudo> runs.  To combat this the
228 C<LD_*>, C<_RLD_*>, C<SHLIB_PATH> (HP-UX only), and C<LIBPATH> (AIX
229 only) environment variables are removed from the environment passed
230 on to all commands executed.  B<sudo> will also remove the C<IFS>,
231 C<ENV>, C<BASH_ENV>, C<KRB_CONF>, C<KRBCONFDIR>, C<KRBTKFILE>,
232 C<KRB5_CONFIG>, C<LOCALDOMAIN>, C<RES_OPTIONS>, C<HOSTALIASES>,
233 C<NLSPATH>, C<PATH_LOCALE>, C<TERMINFO>, C<TERMINFO_DIRS> and
234 C<TERMPATH> variables as they too can pose a threat.  If the
235 C<TERMCAP> variable is set and is a pathname, it too is ignored.
236 Additionally, if the C<LC_*> or C<LANGUAGE> variables contain the
237 C</> or C<%> characters, they are ignored.  If B<sudo> has been
238 compiled with SecurID support, the C<VAR_ACE>, C<USR_ACE> and
239 C<DLC_ACE> variables are cleared as well.  The list of environment
240 variables that B<sudo> clears is contained in the output of
241 C<sudo -V> when run as root.
242
243 To prevent command spoofing, B<sudo> checks "." and "" (both denoting
244 current directory) last when searching for a command in the user's
245 PATH (if one or both are in the PATH).  Note, however, that the
246 actual C<PATH> environment variable is I<not> modified and is passed
247 unchanged to the program that B<sudo> executes.
248
249 For security reasons, if your OS supports shared libraries and does
250 not disable user-defined library search paths for setuid programs
251 (most do), you should either use a linker option that disables this
252 behavior or link B<sudo> statically.
253
254 B<sudo> will check the ownership of its timestamp directory
255 (F<@timedir@> by default) and ignore the directory's contents if
256 it is not owned by root and only writable by root.  On systems that
257 allow non-root users to give away files via chown(2), if the timestamp
258 directory is located in a directory writable by anyone (e.g.: F</tmp>),
259 it is possible for a user to create the timestamp directory before
260 B<sudo> is run.  However, because B<sudo> checks the ownership and
261 mode of the directory and its contents, the only damage that can
262 be done is to "hide" files by putting them in the timestamp dir.
263 This is unlikely to happen since once the timestamp dir is owned
264 by root and inaccessible by any other user the user placing files
265 there would be unable to get them back out.  To get around this
266 issue you can use a directory that is not world-writable for the
267 timestamps (F</var/adm/sudo> for instance) or create F<@timedir@>
268 with the appropriate owner (root) and permissions (0700) in the
269 system startup files.
270
271 B<sudo> will not honor timestamps set far in the future.
272 Timestamps with a date greater than current_time + 2 * C<TIMEOUT>
273 will be ignored and sudo will log and complain.  This is done to
274 keep a user from creating his/her own timestamp with a bogus
275 date on systems that allow users to give away files.
276
277 Please note that B<sudo> will only log the command it explicitly
278 runs.  If a user runs a command such as C<sudo su> or C<sudo sh>,
279 subsequent commands run from that shell will I<not> be logged, nor
280 will B<sudo>'s access control affect them.  The same is true for
281 commands that offer shell escapes (including most editors).  Because
282 of this, care must be taken when giving users access to commands
283 via B<sudo> to verify that the command does not inadvertantly give
284 the user an effective root shell.
285
286 =head1 EXAMPLES
287
288 Note: the following examples assume suitable sudoers(5) entries.
289
290 To get a file listing of an unreadable directory:
291
292  % sudo ls /usr/local/protected
293
294 To list the home directory of user yazza on a machine where the
295 filesystem holding ~yazza is not exported as root:
296
297  % sudo -u yazza ls ~yazza
298
299 To edit the F<index.html> file as user www:
300
301  % sudo -u www vi ~www/htdocs/index.html
302
303 To shutdown a machine:
304
305  % sudo shutdown -r +15 "quick reboot"
306
307 To make a usage listing of the directories in the /home
308 partition.  Note that this runs the commands in a sub-shell
309 to make the C<cd> and file redirection work.
310
311  % sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
312
313 =head1 ENVIRONMENT
314
315 B<sudo> utilizes the following environment variables:
316
317  PATH                   Set to a sane value if SECURE_PATH is set
318  SHELL                  Used to determine shell to run with -s option
319  USER                   Set to the target user (root unless the -u option
320                         is specified)
321  HOME                   In -s or -H mode (or if sudo was configured with
322                         the --enable-shell-sets-home option), set to
323                         homedir of the target user.
324  SUDO_PROMPT            Used as the default password prompt
325  SUDO_COMMAND           Set to the command run by sudo
326  SUDO_USER              Set to the login of the user who invoked sudo
327  SUDO_UID               Set to the uid of the user who invoked sudo
328  SUDO_GID               Set to the gid of the user who invoked sudo
329  SUDO_PS1               If set, PS1 will be set to its value
330
331 =head1 FILES
332
333  @sysconfdir@/sudoers           List of who can run what
334  @timedir@              Directory containing timestamps
335
336 =head1 AUTHORS
337
338 Many people have worked on B<sudo> over the years; this
339 version consists of code written primarily by:
340
341         Todd Miller
342         Chris Jepeway
343
344 See the HISTORY file in the B<sudo> distribution or visit
345 http://www.sudo.ws/sudo/history.html for a short history
346 of B<sudo>.
347
348 =head1 BUGS
349
350 If you feel you have found a bug in sudo, please submit a bug report
351 at http://www.sudo.ws/sudo/bugs/
352
353 =head1 DISCLAIMER
354
355 B<Sudo> is provided ``AS IS'' and any express or implied warranties,
356 including, but not limited to, the implied warranties of merchantability
357 and fitness for a particular purpose are disclaimed.
358 See the LICENSE file distributed with B<sudo> for complete details.
359
360 =head1 CAVEATS
361
362 There is no easy way to prevent a user from gaining a root shell if
363 that user has access to commands allowing shell escapes.
364
365 If users have sudo C<ALL> there is nothing to prevent them from creating
366 their own program that gives them a root shell regardless of any '!'
367 elements in the user specification.
368
369 Running shell scripts via B<sudo> can expose the same kernel bugs
370 that make setuid shell scripts unsafe on some operating systems
371 (if your OS supports the /dev/fd/ directory, setuid shell scripts
372 are generally safe).
373
374 =head1 SEE ALSO
375
376 stat(2), login_cap(3), sudoers(5), passwd(5), visudo(8), grep(1), su(1).