OSDN Git Service

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