1SUDO(8)                      MAINTENANCE COMMANDS                      SUDO(8)
2
3
4

NAME

6       sudo, sudoedit - execute a command as another user
7

SYNOPSIS

9       sudo -K -L -V -h -k -l -v
10
11       sudo [-HPSb] [-a auth_type] [-c class⎪-] [-p prompt] [-u username⎪#uid]
12       {-e file [...] ⎪ -i -s command}
13
14       sudoedit [-S] [-a auth_type] [-p prompt] [-u username⎪#uid] file [...]
15

DESCRIPTION

17       sudo allows a permitted user to execute a command as the superuser or
18       another user, as specified in the sudoers file.  The real and effective
19       uid and gid are set to match those of the target user as specified in
20       the passwd file and the group vector is initialized based on the group
21       file (unless the -P option was specified).  If the invoking user is
22       root or if the target user is the same as the invoking user, no pass‐
23       word is required.  Otherwise, sudo requires that users authenticate
24       themselves with a password by default (NOTE: in the default configura‐
25       tion this is the user's password, not the root password).  Once a user
26       has been authenticated, a timestamp is updated and the user may then
27       use sudo without a password for a short period of time (5 minutes
28       unless overridden in sudoers).
29
30       When invoked as sudoedit, the -e option (described below), is implied.
31
32       sudo determines who is an authorized user by consulting the file
33       /etc/sudoers.  By giving sudo the -v flag a user can update the time
34       stamp without running a command. The password prompt itself will also
35       time out if the user's password is not entered within 5 minutes (unless
36       overridden via sudoers).
37
38       If a user who is not listed in the sudoers file tries to run a command
39       via sudo, mail is sent to the proper authorities, as defined at config‐
40       ure time or in the sudoers file (defaults to root).  Note that the mail
41       will not be sent if an unauthorized user tries to run sudo with the -l
42       or -v flags.  This allows users to determine for themselves whether or
43       not they are allowed to use sudo.
44
45       If sudo is run by root and the SUDO_USER environment variable is set,
46       sudo will use this value to determine who the actual user is.  This can
47       be used by a user to log commands through sudo even when a root shell
48       has been invoked.  It also allows the -e flag to remain useful even
49       when being run via a sudo-run script or program.  Note however, that
50       the sudoers lookup is still done for root, not the user specified by
51       SUDO_USER.
52
53       sudo can log both successful and unsuccessful attempts (as well as
54       errors) to syslog(3), a log file, or both.  By default sudo will log
55       via syslog(3) but this is changeable at configure time or via the sudo‐
56       ers file.
57

OPTIONS

59       sudo accepts the following command line options:
60
61       -H  The -H (HOME) option sets the HOME environment variable to the
62           homedir of the target user (root by default) as specified in
63           passwd(5).  By default, sudo does not modify HOME (see set_home and
64           always_set_home in sudoers(5)).
65
66       -K  The -K (sure kill) option is like -k except that it removes the
67           user's timestamp entirely.  Like -k, this option does not require a
68           password.
69
70       -L  The -L (list defaults) option will list out the parameters that may
71           be set in a Defaults line along with a short description for each.
72           This option is useful in conjunction with grep(1).
73
74       -P  The -P (preserve group vector) option causes sudo to preserve the
75           invoking user's group vector unaltered.  By default, sudo will ini‐
76           tialize the group vector to the list of groups the target user is
77           in.  The real and effective group IDs, however, are still set to
78           match the target user.
79
80       -S  The -S (stdin) option causes sudo to read the password from the
81           standard input instead of the terminal device.
82
83       -V  The -V (version) option causes sudo to print the version number and
84           exit.  If the invoking user is already root the -V option will
85           print out a list of the defaults sudo was compiled with as well as
86           the machine's local network addresses.
87
88       -a  The -a (authentication type) option causes sudo to use the speci‐
89           fied authentication type when validating the user, as allowed by
90           /etc/login.conf.  The system administrator may specify a list of
91           sudo-specific authentication methods by adding an "auth-sudo" entry
92           in /etc/login.conf.  This option is only available on systems that
93           support BSD authentication where sudo has been configured with the
94           --with-bsdauth option.
95
96       -b  The -b (background) option tells sudo to run the given command in
97           the background.  Note that if you use the -b option you cannot use
98           shell job control to manipulate the process.
99
100       -c  The -c (class) option causes sudo to run the specified command with
101           resources limited by the specified login class.  The class argument
102           can be either a class name as defined in /etc/login.conf, or a sin‐
103           gle '-' character.  Specifying a class of - indicates that the com‐
104           mand should be run restricted by the default login capabilities for
105           the user the command is run as.  If the class argument specifies an
106           existing user class, the command must be run as root, or the sudo
107           command must be run from a shell that is already root.  This option
108           is only available on systems with BSD login classes where sudo has
109           been configured with the --with-logincap option.
110
111       -e  The -e (edit) option indicates that, instead of running a command,
112           the user wishes to edit one or more files.  In lieu of a command,
113           the string "sudoedit" is used when consulting the sudoers file.  If
114           the user is authorized by sudoers the following steps are taken:
115
116           1.      Temporary copies are made of the files to be edited with
117                   the owner set to the invoking user.
118
119           2.      The editor specified by the VISUAL or EDITOR environment
120                   variables is run to edit the temporary files.  If neither
121                   VISUAL nor EDITOR are set, the program listed in the editor
122                   sudoers variable is used.
123
124           3.      If they have been modified, the temporary files are copied
125                   back to their original location and the temporary versions
126                   are removed.
127
128           If the specified file does not exist, it will be created.  Note
129           that unlike most commands run by sudo, the editor is run with the
130           invoking user's environment unmodified.  If, for some reason, sudo
131           is unable to update a file with its edited version, the user will
132           receive a warning and the edited copy will remain in a temporary
133           file.
134
135       -h  The -h (help) option causes sudo to print a usage message and exit.
136
137       -i  The -i (simulate initial login) option runs the shell specified in
138           the passwd(5) entry of the user that the command is being run as.
139           The command name argument given to the shell begins with a - to
140           tell the shell to run as a login shell.  sudo attempts to change to
141           that user's home directory before running the shell.  It also ini‐
142           tializes the environment, leaving TERM unchanged, setting HOME,
143           SHELL, USER, LOGNAME, and PATH, and unsetting all other environment
144           variables.  Note that because the shell to use is determined before
145           the sudoers file is parsed, a runas_default setting in sudoers will
146           specify the user to run the shell as but will not affect which
147           shell is actually run.
148
149       -k  The -k (kill) option to sudo invalidates the user's timestamp by
150           setting the time on it to the epoch.  The next time sudo is run a
151           password will be required.  This option does not require a password
152           and was added to allow a user to revoke sudo permissions from a
153           .logout file.
154
155       -l  The -l (list) option will list out the allowed (and forbidden) com‐
156           mands for the user on the current host.
157
158       -p  The -p (prompt) option allows you to override the default password
159           prompt and use a custom one.  The following percent (`%') escapes
160           are supported:
161
162           %u      expanded to the invoking user's login name
163
164           %U      expanded to the login name of the user the command will be
165                   run as (defaults to root)
166
167           %h      expanded to the local hostname without the domain name
168
169           %H      expanded to the local hostname including the domain name
170                   (on if the machine's hostname is fully qualified or the
171                   fqdn sudoers option is set)
172
173           %%      two consecutive % characters are collapsed into a single %
174                   character
175
176       -s  The -s (shell) option runs the shell specified by the SHELL envi‐
177           ronment variable if it is set or the shell as specified in
178           passwd(5).
179
180       -u  The -u (user) option causes sudo to run the specified command as a
181           user other than root.  To specify a uid instead of a username, use
182           #uid.  Note that if the targetpw Defaults option is set (see sudo‐
183           ers(5)) it is not possible to run commands with a uid not listed in
184           the password database.
185
186       -v  If given the -v (validate) option, sudo will update the user's
187           timestamp, prompting for the user's password if necessary.  This
188           extends the sudo timeout for another 5 minutes (or whatever the
189           timeout is set to in sudoers) but does not run a command.
190
191       --  The -- flag indicates that sudo should stop processing command line
192           arguments.  It is most useful in conjunction with the -s flag.
193

RETURN VALUES

195       Upon successful execution of a program, the return value from sudo will
196       simply be the return value of the program that was executed.
197
198       Otherwise, sudo quits with an exit value of 1 if there is a configura‐
199       tion/permission problem or if sudo cannot execute the given command.
200       In the latter case the error string is printed to stderr.  If sudo can‐
201       not stat(2) one or more entries in the user's PATH an error is printed
202       on stderr.  (If the directory does not exist or if it is not really a
203       directory, the entry is ignored and no error is printed.)  This should
204       not happen under normal circumstances.  The most common reason for
205       stat(2) to return "permission denied" is if you are running an auto‐
206       mounter and one of the directories in your PATH is on a machine that is
207       currently unreachable.
208

SECURITY NOTES

210       sudo tries to be safe when executing external commands.  Variables that
211       control how dynamic loading and binding is done can be used to subvert
212       the program that sudo runs.  To combat this the LD_*, _RLD_*,
213       SHLIB_PATH (HP-UX only), and LIBPATH (AIX only) environment variables
214       are removed from the environment passed on to all commands executed.
215       sudo will also remove the IFS, CDPATH, ENV, BASH_ENV, KRB_CONF, KRB‐
216       CONFDIR, KRBTKFILE, KRB5_CONFIG, LOCALDOMAIN, RES_OPTIONS, HOSTALIASES,
217       NLSPATH, PATH_LOCALE, TERMINFO, TERMINFO_DIRS and TERMPATH variables as
218       they too can pose a threat.  If the TERMCAP variable is set and is a
219       pathname, it too is ignored.  Additionally, if the LC_* or LANGUAGE
220       variables contain the / or % characters, they are ignored.  Environment
221       variables with a value beginning with () are also removed as they could
222       be interpreted as bash functions.  If sudo has been compiled with
223       SecurID support, the VAR_ACE, USR_ACE and DLC_ACE variables are cleared
224       as well.  The list of environment variables that sudo clears is con‐
225       tained in the output of sudo -V when run as root.
226
227       To prevent command spoofing, sudo checks "." and "" (both denoting cur‐
228       rent directory) last when searching for a command in the user's PATH
229       (if one or both are in the PATH).  Note, however, that the actual PATH
230       environment variable is not modified and is passed unchanged to the
231       program that sudo executes.
232
233       For security reasons, if your OS supports shared libraries and does not
234       disable user-defined library search paths for setuid programs (most
235       do), you should either use a linker option that disables this behavior
236       or link sudo statically.
237
238       sudo will check the ownership of its timestamp directory (/var/run/sudo
239       by default) and ignore the directory's contents if it is not owned by
240       root and only writable by root.  On systems that allow non-root users
241       to give away files via chown(2), if the timestamp directory is located
242       in a directory writable by anyone (e.g.: /tmp), it is possible for a
243       user to create the timestamp directory before sudo is run.  However,
244       because sudo checks the ownership and mode of the directory and its
245       contents, the only damage that can be done is to "hide" files by
246       putting them in the timestamp dir.  This is unlikely to happen since
247       once the timestamp dir is owned by root and inaccessible by any other
248       user the user placing files there would be unable to get them back out.
249       To get around this issue you can use a directory that is not world-
250       writable for the timestamps (/var/adm/sudo for instance) or create
251       /var/run/sudo with the appropriate owner (root) and permissions (0700)
252       in the system startup files.
253
254       sudo will not honor timestamps set far in the future.  Timestamps with
255       a date greater than current_time + 2 * TIMEOUT will be ignored and sudo
256       will log and complain.  This is done to keep a user from creating
257       his/her own timestamp with a bogus date on systems that allow users to
258       give away files.
259
260       Please note that sudo will only log the command it explicitly runs.  If
261       a user runs a command such as sudo su or sudo sh, subsequent commands
262       run from that shell will not be logged, nor will sudo's access control
263       affect them.  The same is true for commands that offer shell escapes
264       (including most editors).  Because of this, care must be taken when
265       giving users access to commands via sudo to verify that the command
266       does not inadvertently give the user an effective root shell.
267

ENVIRONMENT

269       sudo utilizes the following environment variables:
270
271        EDITOR                 Default editor to use in -e (sudoedit) mode if
272                               VISUAL is not set
273
274        HOME                   In -s or -H mode (or if sudo was configured with
275                               the --enable-shell-sets-home option), set to
276                               homedir of the target user
277
278        PATH                   Set to a sane value if sudo was configured with
279                               the --with-secure-path option
280
281        SHELL                  Used to determine shell to run with -s option
282
283        SUDO_PROMPT            Used as the default password prompt
284
285        SUDO_COMMAND           Set to the command run by sudo
286
287        SUDO_USER              Set to the login of the user who invoked sudo
288
289        SUDO_UID               Set to the uid of the user who invoked sudo
290
291        SUDO_GID               Set to the gid of the user who invoked sudo
292
293        SUDO_PS1               If set, PS1 will be set to its value
294
295        USER                   Set to the target user (root unless the -u option
296                               is specified)
297
298        VISUAL                 Default editor to use in -e (sudoedit) mode
299

FILES

301        /etc/sudoers           List of who can run what
302        /var/run/sudo              Directory containing timestamps
303

EXAMPLES

305       Note: the following examples assume suitable sudoers(5) entries.
306
307       To get a file listing of an unreadable directory:
308
309        $ sudo ls /usr/local/protected
310
311       To list the home directory of user yazza on a machine where the file
312       system holding ~yazza is not exported as root:
313
314        $ sudo -u yazza ls ~yazza
315
316       To edit the index.html file as user www:
317
318        $ sudo -u www vi ~www/htdocs/index.html
319
320       To shutdown a machine:
321
322        $ sudo shutdown -r +15 "quick reboot"
323
324       To make a usage listing of the directories in the /home partition.
325       Note that this runs the commands in a sub-shell to make the cd and file
326       redirection work.
327
328        $ sudo sh -c "cd /home ; du -s * ⎪ sort -rn > USAGE"
329

SEE ALSO

331       grep(1), su(1), stat(2), login_cap(3), sudoers(5), passwd(5), visudo(8)
332

AUTHORS

334       Many people have worked on sudo over the years; this version consists
335       of code written primarily by:
336
337               Todd Miller
338               Chris Jepeway
339
340       See the HISTORY file in the sudo distribution or visit
341       http://www.sudo.ws/sudo/history.html for a short history of sudo.
342

CAVEATS

344       There is no easy way to prevent a user from gaining a root shell if
345       that user is allowed to run arbitrary commands via sudo.  Also, many
346       programs (such as editors) allow the user to run commands via shell
347       escapes, thus avoiding sudo's checks.  However, on most systems it is
348       possible to prevent shell escapes with sudo's noexec functionality.
349       See the sudoers(5) manual for details.
350
351       It is not meaningful to run the cd command directly via sudo, e.g.
352
353        $ sudo cd /usr/local/protected
354
355       since when whe command exits the parent process (your shell) will still
356       be the same.  Please see the EXAMPLES section for more information.
357
358       If users have sudo ALL there is nothing to prevent them from creating
359       their own program that gives them a root shell regardless of any '!'
360       elements in the user specification.
361
362       Running shell scripts via sudo can expose the same kernel bugs that
363       make setuid shell scripts unsafe on some operating systems (if your OS
364       has a /dev/fd/ directory, setuid shell scripts are generally safe).
365

BUGS

367       If you feel you have found a bug in sudo, please submit a bug report at
368       http://www.sudo.ws/sudo/bugs/
369

SUPPORT

371       Commercial support is available for sudo, see
372       http://www.sudo.ws/sudo/support.html for details.
373
374       Limited free support is available via the sudo-users mailing list, see
375       http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search
376       the archives.
377

DISCLAIMER

379       Sudo is provided ``AS IS'' and any express or implied warranties,
380       including, but not limited to, the implied warranties of merchantabil‐
381       ity and fitness for a particular purpose are disclaimed.  See the
382       LICENSE file distributed with sudo or
383       http://www.sudo.ws/sudo/license.html for complete details.
384
385
386
3871.6.8p12                         June 20, 2005                         SUDO(8)
Impressum