summaryrefslogtreecommitdiffstats
path: root/login-utils/runuser.1
blob: 939aad351e428ed7bbddc5169bc94893c106fdff (plain)
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
'\" t
.\"     Title: runuser
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.15
.\"      Date: 2022-05-11
.\"    Manual: User Commands
.\"    Source: util-linux 2.38.1
.\"  Language: English
.\"
.TH "RUNUSER" "1" "2022-05-11" "util\-linux 2.38.1" "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"
runuser \- run a command with substitute user and group ID
.SH "SYNOPSIS"
.sp
\fBrunuser\fP [options] \fB\-u\fP \fIuser\fP [[\-\-] \fIcommand\fP [\fIargument\fP...]]
.sp
\fBrunuser\fP [options] [\fB\-\fP] [\fIuser\fP [\fIargument\fP...]]
.SH "DESCRIPTION"
.sp
\fBrunuser\fP can be used to run commands with a substitute user and group ID. If the option \fB\-u\fP is not given, \fBrunuser\fP falls back to \fBsu\fP\-compatible semantics and a shell is executed. The difference between the commands \fBrunuser\fP and \fBsu\fP is that \fBrunuser\fP does not ask for a password (because it may be executed by the root user only) and it uses a different PAM configuration. The command \fBrunuser\fP does not have to be installed with set\-user\-ID permissions.
.sp
If the PAM session is not required, then the recommended solution is to use the \fBsetpriv\fP(1) command.
.sp
When called without arguments, \fBrunuser\fP defaults to running an interactive shell as \fIroot\fP.
.sp
For backward compatibility, \fBrunuser\fP defaults to not changing the current directory and to setting only the environment variables \fBHOME\fP and \fBSHELL\fP (plus \fBUSER\fP and \fBLOGNAME\fP if the target \fIuser\fP is not root). This version of \fBrunuser\fP uses PAM for session management.
.sp
Note that \fBrunuser\fP in all cases use PAM (pam_getenvlist()) 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 \fBrunuser\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
The primary group to be used. This option is allowed for 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
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.  sp -1
.  IP \(bu 2.3
.\}
clears all the environment variables except for \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\-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 TIOCSTI ioctl terminal injection and other security attacks against terminal file descriptors. The entire session can also be moved to the background (e.g., \fBrunuser \-\-pty\fP \fB\-u\fP \fIusername\fP \fB\-\-\fP \fIcommand\fP \fB&\fP). If the pseudo\-terminal is enabled, then \fBrunuser\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" | runuser \-\-pty \-u\fP \fIuser\fP), then the \fBECHO\fP flag for the pseudo\-terminal is disabled to avoid messy output.
.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. The option is ignored if the option \fB\-\-login\fP is specified.
.RE
.sp
\fB\-s\fP, \fB\-\-shell\fP=\fIshell\fP
.RS 4
Run the specified \fIshell\fP instead of the default. 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
.sp
If the target user has a restricted shell (i.e., not listed in \fI/etc/shells\fP), then the \fB\-\-shell\fP option and the \fBSHELL\fP environment variables are ignored unless the calling user is root.
.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\-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 "CONFIG FILES"
.sp
\fBrunuser\fP reads the \fI/etc/default/runuser\fP and \fI/etc/login.defs\fP configuration files. The following configuration items are relevant for \fBrunuser\fP:
.sp
\fBENV_PATH\fP (string)
.RS 4
Defines the PATH 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 \fBrunuser\fP initializes \fBPATH\fP.
.RE
.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)).
.SH "EXIT STATUS"
.sp
\fBrunuser\fP normally returns the exit status of the command it executed. If the command was killed by a signal, \fBrunuser\fP returns the number of the signal plus 128.
.sp
Exit status generated by \fBrunuser\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/runuser\fP
.RS 4
default PAM configuration file
.RE
.sp
\fI/etc/pam.d/runuser\-l\fP
.RS 4
PAM configuration file if \fB\-\-login\fP is specified
.RE
.sp
\fI/etc/default/runuser\fP
.RS 4
runuser specific logindef config file
.RE
.sp
\fI/etc/login.defs\fP
.RS 4
global logindef config file
.RE
.SH "HISTORY"
.sp
This \fBrunuser\fP command was derived from coreutils\(aq \fBsu\fP, which was based on an implementation by David MacKenzie, and the Fedora \fBrunuser\fP command by Dan Walsh.
.SH "SEE ALSO"
.sp
\fBsetpriv\fP(1),
\fBsu\fP(1),
\fBlogin.defs\fP(5),
\fBshells\fP(5),
\fBpam\fP(8)
.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 \fBrunuser\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" "."