1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
'\" t
.\" Title: su
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
.\" Date: 2024-03-20
.\" Manual: User Commands
.\" Source: util-linux 2.40
.\" Language: English
.\"
.TH "SU" "1" "2024-03-20" "util\-linux 2.40" "User Commands"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
. mso www.tmac
. am URL
. ad l
. .
. am MTO
. ad l
. .
. LINKSTYLE blue R < >
.\}
.SH "NAME"
su \- run a command with substitute user and group ID
.SH "SYNOPSIS"
.sp
\fBsu\fP [options] [\fB\-\fP] [\fIuser\fP [\fIargument\fP...]]
.SH "DESCRIPTION"
.sp
\fBsu\fP allows commands to be run with a substitute user and group ID.
.sp
When called with no \fIuser\fP specified, \fBsu\fP defaults to running an interactive shell as \fIroot\fP. When \fIuser\fP is specified, additional \fIargument\fPs can be supplied, in which case they are passed to the shell.
.sp
For backward compatibility, \fBsu\fP defaults to not change the current directory and to only set the environment variables \fBHOME\fP and \fBSHELL\fP (plus \fBUSER\fP and \fBLOGNAME\fP if the target \fIuser\fP is not root). It is recommended to always use the \fB\-\-login\fP option (instead of its shortcut \fB\-\fP) to avoid side effects caused by mixing environments.
.sp
This version of \fBsu\fP uses PAM for authentication, account and session management. Some configuration options found in other \fBsu\fP implementations, such as support for a wheel group, have to be configured via PAM.
.sp
\fBsu\fP 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 \fBrunuser\fP(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 \fBsetpriv\fP(1).
.sp
Note that \fBsu\fP in all cases uses PAM (\fBpam_getenvlist\fP(3)) to do the final environment modification. Command\-line options such as \fB\-\-login\fP and \fB\-\-preserve\-environment\fP affect the environment before it is modified by PAM.
.sp
Since version 2.38 \fBsu\fP resets process resource limits RLIMIT_NICE, RLIMIT_RTPRIO, RLIMIT_FSIZE, RLIMIT_AS and RLIMIT_NOFILE.
.SH "OPTIONS"
.sp
\fB\-c\fP, \fB\-\-command\fP=\fIcommand\fP
.RS 4
Pass \fIcommand\fP to the shell with the \fB\-c\fP option.
.RE
.sp
\fB\-f\fP, \fB\-\-fast\fP
.RS 4
Pass \fB\-f\fP to the shell, which may or may not be useful, depending on the shell.
.RE
.sp
\fB\-g\fP, \fB\-\-group\fP=\fIgroup\fP
.RS 4
Specify the primary group. This option is available to the root user only.
.RE
.sp
\fB\-G\fP, \fB\-\-supp\-group\fP=\fIgroup\fP
.RS 4
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 \fB\-\-group\fP is not specified.
.RE
.sp
\fB\-\fP, \fB\-l\fP, \fB\-\-login\fP
.RS 4
Start the shell as a login shell with an environment similar to a real login.
.sp
Note that on systemd\-based systems, a new session may be defined as a real
entry point to the system. However, \fBsu\fP does not create a real session (by
PAM) from this point of view. You need to use tools like \fBsystemd\-run\fP or
\fBmachinectl\fP to initiate a complete, real session.
.sp
\fBsu\fP does:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
clears all the environment variables except \fBTERM\fP and variables specified by \fB\-\-whitelist\-environment\fP
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
initializes the environment variables \fBHOME\fP, \fBSHELL\fP, \fBUSER\fP, \fBLOGNAME\fP, and \fBPATH\fP
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
changes to the target user\(cqs home directory
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
sets argv[0] of the shell to \*(Aq\fB\-\fP\*(Aq in order to make the shell a login shell
.RE
.RE
.sp
\fB\-m\fP, \fB\-p\fP, \fB\-\-preserve\-environment\fP
.RS 4
Preserve the entire environment, i.e., do not set \fBHOME\fP, \fBSHELL\fP, \fBUSER\fP or \fBLOGNAME\fP. This option is ignored if the option \fB\-\-login\fP is specified.
.RE
.sp
\fB\-P\fP, \fB\-\-pty\fP
.RS 4
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 \fBTIOCSTI\fP ioctl terminal injection and other security attacks against terminal file descriptors. The entire session can also be moved to the background (e.g., \fBsu \-\-pty\fP \fB\-\fP \fIusername\fP \fB\-c\fP \fIapplication\fP \fB&\fP). If the pseudo\-terminal is enabled, then \fBsu\fP works as a proxy between the sessions (sync stdin and stdout).
.sp
This feature is mostly designed for interactive sessions. If the standard input is not a terminal, but for example a pipe (e.g., \fBecho "date" | su \-\-pty\fP), then the \fBECHO\fP flag for the pseudo\-terminal is disabled to avoid messy output.
.RE
.sp
\fB\-s\fP, \fB\-\-shell\fP=\fIshell\fP
.RS 4
Run the specified \fIshell\fP instead of the default. If the target user has a restricted shell (i.e., not listed in \fI/etc/shells\fP), the \fB\-\-shell\fP option and the \fBSHELL\fP environment variables are ignored unless the calling user is root.
.sp
The shell to run is selected according to the following rules, in order:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
the shell specified with \fB\-\-shell\fP
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
the shell specified in the environment variable \fBSHELL\fP, if the \fB\-\-preserve\-environment\fP option is used
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
the shell listed in the passwd entry of the target user
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
. sp -1
. IP \(bu 2.3
.\}
/bin/sh
.RE
.RE
.sp
\fB\-\-session\-command=\fP\fIcommand\fP
.RS 4
Same as \fB\-c\fP, but do not create a new session. (Discouraged.)
.RE
.sp
\fB\-T\fP, \fB\-\-no\-pty\fP*
.RS 4
Do not create a pseudo\-terminal, opposite of \fB\-\-pty\fP and \fB\-P\fP.
Note that running without a pseudo\-terminal opens the security risk of privilege escalation through TIOCSTI/TIOCLINUX ioctl command injection.
.RE
.sp
\fB\-w\fP, \fB\-\-whitelist\-environment\fP=\fIlist\fP
.RS 4
Don\(cqt reset the environment variables specified in the comma\-separated \fIlist\fP when clearing the environment for \fB\-\-login\fP. The whitelist is ignored for the environment variables \fBHOME\fP, \fBSHELL\fP, \fBUSER\fP, \fBLOGNAME\fP, and \fBPATH\fP.
.RE
.sp
\fB\-h\fP, \fB\-\-help\fP
.RS 4
Display help text and exit.
.RE
.sp
\fB\-V\fP, \fB\-\-version\fP
.RS 4
Print version and exit.
.RE
.SH "SIGNALS"
.sp
Upon receiving either \fBSIGINT\fP, \fBSIGQUIT\fP or \fBSIGTERM\fP, \fBsu\fP terminates its child and afterwards terminates itself with the received signal. The child is terminated by \fBSIGTERM\fP, after unsuccessful attempt and 2 seconds of delay the child is killed by \fBSIGKILL\fP.
.SH "CONFIG FILES"
.sp
\fBsu\fP reads the \fI/etc/default/su\fP and \fI/etc/login.defs\fP configuration files. The following configuration items are relevant for \fBsu\fP:
.sp
\fBFAIL_DELAY\fP (number)
.RS 4
Delay in seconds in case of an authentication failure. The number must be a non\-negative integer.
.RE
.sp
\fBENV_PATH\fP (string)
.RS 4
Defines the \fBPATH\fP environment variable for a regular user. The default value is \fI/usr/local/bin:/bin:/usr/bin\fP.
.RE
.sp
\fBENV_ROOTPATH\fP (string), \fBENV_SUPATH\fP (string)
.RS 4
Defines the \fBPATH\fP environment variable for root. \fBENV_SUPATH\fP takes precedence. The default value is \fI/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\fP.
.RE
.sp
\fBALWAYS_SET_PATH\fP (boolean)
.RS 4
If set to \fIyes\fP and \fB\-\-login\fP and \fB\-\-preserve\-environment\fP were not specified \fBsu\fP initializes \fBPATH\fP.
.sp
The environment variable \fBPATH\fP may be different on systems where \fI/bin\fP and \fI/sbin\fP are merged into \fI/usr\fP; this variable is also affected by the \fB\-\-login\fP command\-line option and the PAM system setting (e.g., \fBpam_env\fP(8)).
.RE
.SH "EXIT STATUS"
.sp
\fBsu\fP normally returns the exit status of the command it executed. If the command was killed by a signal, \fBsu\fP returns the number of the signal plus 128.
.sp
Exit status generated by \fBsu\fP itself:
.sp
1
.RS 4
Generic error before executing the requested command
.RE
.sp
126
.RS 4
The requested command could not be executed
.RE
.sp
127
.RS 4
The requested command was not found
.RE
.SH "FILES"
.sp
\fI/etc/pam.d/su\fP
.RS 4
default PAM configuration file
.RE
.sp
\fI/etc/pam.d/su\-l\fP
.RS 4
PAM configuration file if \fB\-\-login\fP is specified
.RE
.sp
\fI/etc/default/su\fP
.RS 4
command specific logindef config file
.RE
.sp
\fI/etc/login.defs\fP
.RS 4
global logindef config file
.RE
.SH "NOTES"
.sp
For security reasons, \fBsu\fP always logs failed log\-in attempts to the \fIbtmp\fP file, but it does not write to the \fIlastlog\fP file at all. This solution can be used to control \fBsu\fP behavior by PAM configuration. If you want to use the \fBpam_lastlog\fP(8) module to print warning message about failed log\-in attempts then \fBpam_lastlog\fP(8) has to be configured to update the \fIlastlog\fP file as well. For example by:
.RS 3
.ll -.6i
.sp
session required pam_lastlog.so nowtmp
.br
.RE
.ll
.SH "HISTORY"
.sp
This \fBsu\fP command was derived from coreutils\*(Aq \fBsu\fP, which was based on an implementation by David MacKenzie. The util\-linux version has been refactored by Karel Zak.
.SH "SEE ALSO"
.sp
\fBsetpriv\fP(1),
\fBlogin.defs\fP(5),
\fBshells\fP(5),
\fBpam\fP(8),
\fBrunuser\fP(1)
.SH "REPORTING BUGS"
.sp
For bug reports, use the issue tracker at \c
.URL "https://github.com/util\-linux/util\-linux/issues" "" "."
.SH "AVAILABILITY"
.sp
The \fBsu\fP command is part of the util\-linux package which can be downloaded from \c
.URL "https://www.kernel.org/pub/linux/utils/util\-linux/" "Linux Kernel Archive" "."
|