]> git.ipfire.org Git - thirdparty/util-linux.git/blob - login-utils/su.1.adoc
70c1e0cc48a98da670726d76920d1face7b24eac
[thirdparty/util-linux.git] / login-utils / su.1.adoc
1 //po4a: entry man manual
2 = su(1)
3 :doctype: manpage
4 :man manual: User Commands
5 :man source: util-linux {release-version}
6 :page-layout: base
7 :command: su
8 :colon: :
9
10 == NAME
11
12 su - run a command with substitute user and group ID
13
14 == SYNOPSIS
15
16 *su* [options] [*-*] [_user_ [_argument_...]]
17
18 == DESCRIPTION
19
20 *su* allows commands to be run with a substitute user and group ID.
21
22 When called with no _user_ specified, *su* defaults to running an interactive shell as _root_. When _user_ is specified, additional __argument__s can be supplied, in which case they are passed to the shell.
23
24 For backward compatibility, *su* defaults to not change the current directory and to only set the environment variables *HOME* and *SHELL* (plus *USER* and *LOGNAME* if the target _user_ is not root). It is recommended to always use the *--login* option (instead of its shortcut *-*) to avoid side effects caused by mixing environments.
25
26 This version of *su* uses PAM for authentication, account and session management. Some configuration options found in other *su* implementations, such as support for a wheel group, have to be configured via PAM.
27
28 *su* is mostly designed for unprivileged users, the recommended solution for privileged users (e.g., scripts executed by root) is to use non-set-user-ID command *runuser*(1) that does not require authentication and provides separate PAM configuration. If the PAM session is not required at all then the recommended solution is to use command *setpriv*(1).
29
30 Note that *su* in all cases uses PAM (*pam_getenvlist*(3)) to do the final environment modification. Command-line options such as *--login* and *--preserve-environment* affect the environment before it is modified by PAM.
31
32 Since version 2.38 *su* resets process resource limits RLIMIT_NICE, RLIMIT_RTPRIO, RLIMIT_FSIZE, RLIMIT_AS and RLIMIT_NOFILE.
33
34 == OPTIONS
35
36 *-c*, **--command**=__command__::
37 Pass _command_ to the shell with the *-c* option.
38
39 *-f*, *--fast*::
40 Pass *-f* to the shell, which may or may not be useful, depending on the shell.
41
42 *-g*, **--group**=__group__::
43 Specify the primary group. This option is available to the root user only.
44
45 *-G*, **--supp-group**=__group__::
46 Specify a supplementary group. This option is available to the root user only. The first specified supplementary group is also used as a primary group if the option *--group* is not specified.
47
48 *-*, *-l*, *--login*::
49 Start the shell as a login shell with an environment similar to a real login:
50
51 * clears all the environment variables except *TERM* and variables specified by *--whitelist-environment*
52 * initializes the environment variables *HOME*, *SHELL*, *USER*, *LOGNAME*, and *PATH*
53 * changes to the target user's home directory
54 * sets argv[0] of the shell to '*-*' in order to make the shell a login shell
55
56 *-m*, *-p*, *--preserve-environment*::
57 Preserve the entire environment, i.e., do not set *HOME*, *SHELL*, *USER* or *LOGNAME*. This option is ignored if the option *--login* is specified.
58
59 *-P*, *--pty*::
60 Create a pseudo-terminal for the session. The independent terminal provides better security as the user does not share a terminal with the original session. This can be used to avoid TIOCSTI ioctl terminal injection and other security attacks against terminal file descriptors. The entire session can also be moved to the background (e.g., "su --pty - username -c application &"). If the pseudo-terminal is enabled, then *su* works as a proxy between the sessions (copy stdin and stdout).
61 +
62 This feature is mostly designed for interactive sessions. If the standard input is not a terminal, but for example a pipe (e.g., echo "date" | su --pty), then the *ECHO* flag for the pseudo-terminal is disabled to avoid messy output.
63
64 *-s*, **--shell**=__shell__::
65 Run the specified _shell_ instead of the default. The shell to run is selected according to the following rules, in order:
66
67 * the shell specified with *--shell*
68 * the shell specified in the environment variable *SHELL*, if the *--preserve-environment* option is used
69 * the shell listed in the passwd entry of the target user
70 * /bin/sh
71
72 If the target user has a restricted shell (i.e., not listed in _/etc/shells_), the *--shell* option and the *SHELL* environment variables are ignored unless the calling user is root.
73
74 **--session-command=**__command__::
75 Same as *-c*, but do not create a new session. (Discouraged.)
76
77 *-w*, **--whitelist-environment**=__list__::
78 Don't reset the environment variables specified in the comma-separated _list_ when clearing the environment for *--login*. The whitelist is ignored for the environment variables *HOME*, *SHELL*, *USER*, *LOGNAME*, and *PATH*.
79
80 include::man-common/help-version.adoc[]
81
82 == SIGNALS
83
84 Upon receiving either *SIGINT*, *SIGQUIT* or *SIGTERM*, *su* terminates its child and afterwards terminates itself with the received signal. The child is terminated by *SIGTERM*, after unsuccessful attempt and 2 seconds of delay the child is killed by *SIGKILL*.
85
86 == CONFIG FILES
87
88 //TRANSLATORS: Keep {colon} untranslated
89 *su* reads the _/etc/default/su_ and _/etc/login.defs_ configuration files. The following configuration items are relevant for *su*{colon}
90
91 *FAIL_DELAY* (number)::
92 Delay in seconds in case of an authentication failure. The number must be a non-negative integer.
93
94 *ENV_PATH* (string)::
95 Defines the *PATH* environment variable for a regular user. The default value is _/usr/local/bin:/bin:/usr/bin_.
96
97 *ENV_ROOTPATH* (string)::
98 *ENV_SUPATH* (string)::
99 Defines the *PATH* environment variable for root. *ENV_SUPATH* takes precedence. The default value is _/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_.
100
101 *ALWAYS_SET_PATH* (boolean)::
102 If set to _yes_ and *--login* and *--preserve-environment* were not specified *su* initializes *PATH*.
103 +
104 The environment variable *PATH* may be different on systems where _/bin_ and _/sbin_ are merged into _/usr_; this variable is also affected by the *--login* command-line option and the PAM system setting (e.g., *pam_env*(8)).
105
106 == EXIT STATUS
107
108 *su* normally returns the exit status of the command it executed. If the command was killed by a signal, *su* returns the number of the signal plus 128.
109
110 Exit status generated by *su* itself:
111
112 1::
113 Generic error before executing the requested command
114 126::
115 The requested command could not be executed
116 127::
117 The requested command was not found
118
119 == FILES
120
121 _/etc/pam.d/su_::
122 default PAM configuration file
123
124 _/etc/pam.d/su-l_::
125 PAM configuration file if *--login* is specified
126
127 _/etc/default/su_::
128 command specific logindef config file
129
130 _/etc/login.defs_::
131 global logindef config file
132
133 == NOTES
134
135 For security reasons, *su* always logs failed log-in attempts to the btmp file, but it does not write to the _lastlog_ file at all. This solution can be used to control *su* behavior by PAM configuration. If you want to use the *pam_lastlog*(8) module to print warning message about failed log-in attempts then *pam_lastlog*(8) has to be configured to update the _lastlog_ file as well. For example by:
136
137 ____
138 session required pam_lastlog.so nowtmp
139 ____
140
141 == HISTORY
142
143 This *su* command was derived from coreutils' *su*, which was based on an implementation by David MacKenzie. The util-linux version has been refactored by Karel Zak.
144
145 == SEE ALSO
146
147 *setpriv*(1),
148 *login.defs*(5),
149 *shells*(5),
150 *pam*(8),
151 *runuser*(1)
152
153 include::man-common/bugreports.adoc[]
154
155 include::man-common/footer.adoc[]
156
157 ifdef::translation[]
158 include::man-common/translation.adoc[]
159 endif::[]