Debian Codegraph @

man/run0.xml

raw
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="run0"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>run0</title>
11 <productname>systemd</productname>
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>run0</refentrytitle>
16 <manvolnum>1</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>run0</refname>
21 <refpurpose>Elevate privileges</refpurpose>
22 </refnamediv>
23
24 <refsynopsisdiv>
25 <cmdsynopsis>
26 <command>run0</command>
27 <arg choice="opt" rep="repeat">OPTIONS</arg>
28 <arg choice="opt" rep="repeat">COMMAND</arg>
29 </cmdsynopsis>
30 </refsynopsisdiv>
31
32 <refsect1>
33 <title>Description</title>
34
35 <para><command>run0</command> may be used to temporarily and interactively acquire elevated or different
36 privileges. It serves a similar purpose as <citerefentry
37 project='man-pages'><refentrytitle>sudo</refentrytitle><manvolnum>8</manvolnum></citerefentry>, but
38 operates differently in a couple of key areas:</para>
39
40 <itemizedlist>
41 <listitem><para>No execution or security context credentials are inherited from the caller into the
42 invoked commands, as they are invoked from a fresh, isolated service forked off by the service manager.
43 </para></listitem>
44
45 <listitem><para>Authentication takes place via <ulink
46 url="https://www.freedesktop.org/wiki/Software/polkit">polkit</ulink>, thus isolating the
47 authentication prompt from the terminal (if possible).</para></listitem>
48
49 <listitem><para>An independent pseudo-tty is allocated for the invoked command, detaching its lifecycle and
50 isolating it for security.</para></listitem>
51
52 <listitem><para>No SetUID/SetGID file access bit functionality is used for the implementation.</para></listitem>
53 </itemizedlist>
54
55 <para>Altogether this should provide a safer and more robust alternative to the <command>sudo</command>
56 mechanism, in particular in OS environments where SetUID/SetGID support is not available (for example by
57 setting the <varname>NoNewPrivileges=</varname> variable in
58 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).</para>
59
60 <para>Any session invoked via <command>run0</command> will run through the
61 <literal>systemd-run0</literal> PAM stack.</para>
62
63 <para>Note that <command>run0</command> is implemented as an alternative multi-call invocation of
64 <citerefentry><refentrytitle>systemd-run</refentrytitle><manvolnum>1</manvolnum></citerefentry>. That is,
65 <command>run0</command> is a symbolic link to <command>systemd-run</command> executable file, and it
66 behaves as <command>run0</command> if it is invoked through the symbolic link, otherwise behaves as
67 <command>systemd-run</command>.</para>
68 </refsect1>
69
70 <refsect1>
71 <title>Options</title>
72
73 <para>The following options are understood:</para>
74
75 <variablelist>
76 <varlistentry>
77 <term><option>--unit=</option></term>
78
79 <listitem><para>Use this unit name instead of an automatically generated one.</para>
80
81 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
82 </varlistentry>
83
84 <varlistentry>
85 <term><option>--property=</option></term>
86
87 <listitem><para>Sets a property of the service unit that is created. This option takes an assignment
88 in the same format as
89 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
90 <command>set-property</command> command.</para>
91
92 <xi:include href="version-info.xml" xpointer="v256"/>
93 </listitem>
94 </varlistentry>
95
96 <varlistentry>
97 <term><option>--description=</option></term>
98
99 <listitem><para>Provide a description for the service unit that is invoked. If not specified,
100 the command itself will be used as a description. See <varname>Description=</varname> in
101 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
102 </para>
103
104 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
105 </varlistentry>
106
107 <varlistentry>
108 <term><option>--slice=</option></term>
109
110 <listitem><para>Make the new <filename>.service</filename> unit part of the specified slice, instead
111 of <filename>user.slice</filename>.</para>
112
113 <xi:include href="version-info.xml" xpointer="v256"/>
114 </listitem>
115 </varlistentry>
116
117 <varlistentry>
118 <term><option>--slice-inherit</option></term>
119
120 <listitem><para>Make the new <filename>.service</filename> unit part of the slice the
121 <command>run0</command> itself has been invoked in. This option may be combined with
122 <option>--slice=</option>, in which case the slice specified via <option>--slice=</option> is placed
123 within the slice the <command>run0</command> command is invoked in.</para>
124
125 <para>Example: consider <command>run0</command> being invoked in the slice
126 <filename>foo.slice</filename>, and the <option>--slice=</option> argument is
127 <filename>bar</filename>. The unit will then be placed under
128 <filename>foo-bar.slice</filename>.</para>
129
130 <xi:include href="version-info.xml" xpointer="v256"/>
131
132 </listitem>
133 </varlistentry>
134
135 <varlistentry>
136 <term><option>--user=</option></term>
137 <term><option>-u</option></term>
138 <term><option>--group=</option></term>
139 <term><option>-g</option></term>
140
141 <listitem><para>Switches to the specified user/group. If not specified defaults to
142 <literal>root</literal>, unless <option>--area=</option> or <option>--empower</option> are used (see
143 below), in which case this defaults to the invoking user.</para>
144
145 <xi:include href="version-info.xml" xpointer="v256"/>
146 </listitem>
147 </varlistentry>
148
149 <varlistentry>
150 <term><option>--nice=</option></term>
151
152 <listitem><para>Runs the invoked session with the specified nice level.</para>
153
154 <xi:include href="version-info.xml" xpointer="v256"/>
155 </listitem>
156 </varlistentry>
157
158 <varlistentry>
159 <term><option>--chdir=</option></term>
160 <term><option>-D</option></term>
161
162 <listitem><para>Runs the invoked session with the specified working directory. If not specified
163 defaults to the client's current working directory if switching to the root user, or the target
164 user's home directory otherwise.</para>
165
166 <xi:include href="version-info.xml" xpointer="v256"/>
167 </listitem>
168 </varlistentry>
169
170 <varlistentry>
171 <term><option>--via-shell</option></term>
172
173 <listitem><para>Invokes the target user's login shell and runs the specified command (if any) via it.</para>
174
175 <xi:include href="version-info.xml" xpointer="v258"/>
176 </listitem>
177 </varlistentry>
178
179 <varlistentry>
180 <term><option>-i</option></term>
181
182 <listitem><para>Shortcut for <option>--via-shell --chdir='~'</option>.</para>
183
184 <xi:include href="version-info.xml" xpointer="v258"/>
185 </listitem>
186 </varlistentry>
187
188 <varlistentry>
189 <term><option>--setenv=<replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term>
190
191 <listitem><para>Runs the invoked session with the specified environment variable set. This parameter
192 may be used more than once to set multiple variables. When <literal>=</literal> and
193 <replaceable>VALUE</replaceable> are omitted, the value of the variable with the same name in the
194 invoking environment will be used.</para>
195
196 <xi:include href="version-info.xml" xpointer="v256"/>
197 </listitem>
198 </varlistentry>
199
200 <varlistentry>
201 <term><option>--background=<replaceable>COLOR</replaceable></option></term>
202
203 <listitem><para>Change the terminal background color to the specified ANSI color as long as the
204 session lasts. If not specified, the background will be tinted in a reddish tone when operating as
205 root, and in a yellowish tone when operating under another UID, as reminder of the changed
206 privileges. The color specified should be an ANSI X3.64 SGR background color, i.e. strings such as
207 <literal>40</literal>, <literal>41</literal>, …, <literal>47</literal>, <literal>48;2;…</literal>,
208 <literal>48;5;…</literal>. See <ulink
209 url="https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters">ANSI
210 Escape Code (Wikipedia)</ulink> for details. Set to an empty string to disable.</para>
211
212 <para>Example: <literal>--background=44</literal> for a blue background.</para>
213
214 <xi:include href="version-info.xml" xpointer="v256"/>
215 </listitem>
216 </varlistentry>
217
218 <varlistentry>
219 <term><option>--pty</option></term>
220 <term><option>--pty-late</option></term>
221 <term><option>--pipe</option></term>
222
223 <listitem><para>Request allocation of a pseudo TTY for the <command>run0</command> session (in case
224 of <option>--pty</option> or <option>--pty-late</option>), or request passing the caller's STDIO file
225 descriptors directly through (in case of <option>--pipe</option>). <option>--pty-late</option> is
226 very similar to <option>--pty</option> but begins the TTY processing only once unit startup is
227 complete, leaving input to any passwords/polkit agents until that time. If neither switch is
228 specified, or if both <option>--pipe</option> and one of
229 <option>--pty</option>/<option>--pty-late</option> are specified, the mode will be picked
230 automatically: if standard input, standard output, and standard error output are all connected to a
231 TTY then a pseudo TTY is allocated (in <option>--pty-late</option> mode unless
232 <option>--no-ask-password</option> is specified in which case <option>--pty</option> is selected),
233 otherwise the relevant file descriptors are passed through directly.</para>
234
235 <para id="v257"><option>--pty</option> and <option>--pipe</option> were added in v257.</para>
236 <para id="v258"><option>--pty-late</option> was added in v258.</para>
237 </listitem>
238 </varlistentry>
239
240 <varlistentry>
241 <term><option>--shell-prompt-prefix=<replaceable>STRING</replaceable></option></term>
242
243 <listitem><para>Set a shell prompt prefix string. This ultimately controls the
244 <varname>$SHELL_PROMPT_PREFIX</varname> environment variable for the invoked program, which is
245 typically imported into the shell prompt. By default – if emojis are supported –, a superhero emoji is
246 shown (🦸). This default may also be changed (or turned off) by passing the
247 <varname>$SYSTEMD_RUN_SHELL_PROMPT_PREFIX</varname> environment variable to <varname>run0</varname>,
248 see below. Set to an empty string to disable shell prompt prefixing.</para>
249
250 <xi:include href="version-info.xml" xpointer="v257"/>
251 </listitem>
252 </varlistentry>
253
254 <varlistentry>
255 <term><option>--lightweight=<replaceable>BOOLEAN</replaceable></option></term>
256
257 <listitem><para>Controls whether to activate the per-user service manager for the target user. By
258 default (unset or set to <option>auto</option>), if the target user is <literal>root</literal> or
259 a system user the per-user service manager is not activated as effect of the <command>run0</command>
260 invocation, otherwise it is.</para>
261
262 <para>This ultimately controls the <varname>$XDG_SESSION_CLASS</varname> environment variable
263 <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
264 respects.</para>
265
266 <xi:include href="version-info.xml" xpointer="v258"/>
267 </listitem>
268 </varlistentry>
269
270 <varlistentry>
271 <term><option>--area=<replaceable>AREA</replaceable></option></term>
272
273 <listitem><para>Controls the "area" of the target account to log into. Areas are secondary home
274 directories within the primary home directory of the target user, i.e. logging into area
275 <literal>foobar</literal> of an account translates to <varname>$HOME</varname> being set to
276 <filename>~/Areas/foobar</filename> on login.</para>
277
278 <para>If this option is used, the default user to transition to changes from root to the calling
279 user's (but <option>--user=</option> takes precedence, see above). Or in other words, just specifying
280 an area without a user is a mechanism to create a new session of the calling user, just with a
281 different area.</para>
282
283 <para>This ultimately controls the <varname>$XDG_AREA</varname> environment variable
284 <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
285 respects.</para>
286
287 <para>For details on the area concept see
288 <citerefentry><refentrytitle>pam_systemd_home</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
289
290 <xi:include href="version-info.xml" xpointer="v258"/>
291 </listitem>
292 </varlistentry>
293
294 <varlistentry>
295 <term><option>--empower</option></term>
296
297 <listitem><para>If specified, run0 will elevate the privileges of the selected user (using
298 <option>--user=</option>) or the current user if no user is explicitly selected. Currently this means
299 we give the invoked process all available capabilities and add the <literal>empower</literal>
300 group as a supplemental group (for which all polkit actions are allowed by default), but other
301 privileges may be granted in the future as well when using this option.</para>
302
303 <para>Note that other (unprivileged) processes of the selected user will have privileges over the
304 invoked process. Consider not using this option in an environment where there might be malicious
305 processes running as the selected user.</para>
306
307 <xi:include href="version-info.xml" xpointer="v259"/></listitem>
308 </varlistentry>
309
310 <varlistentry>
311 <term><option>--same-root-dir</option></term>
312
313 <listitem><para>Execute the <command>run0</command> session in the same root directory that the
314 <command>run0</command> command is executed in.</para>
315
316 <xi:include href="version-info.xml" xpointer="v259"/></listitem>
317 </varlistentry>
318
319 <varlistentry>
320 <term><option>--machine=</option></term>
321
322 <listitem>
323 <para>Execute operation in a local container. Specify a container name to connect to.</para>
324
325 <xi:include href="version-info.xml" xpointer="v256"/>
326 </listitem>
327 </varlistentry>
328
329 <xi:include href="standard-options.xml" xpointer="no-ask-password" />
330 <xi:include href="standard-options.xml" xpointer="help" />
331 <xi:include href="standard-options.xml" xpointer="version" />
332 </variablelist>
333
334 <para>All command line arguments after the first non-option argument become part of the command line of
335 the launched process. If no command line is specified an interactive shell is invoked. The shell to
336 invoke may be controlled through <option>--via-shell</option> - when specified the target user's shell
337 is used - or <option>--setenv=SHELL=…</option>. By default, the <emphasis>originating user's</emphasis> shell
338 is executed if operating locally, or <filename>/bin/sh</filename> when operating with <option>--machine=</option>.</para>
339
340 <para>Note that unlike <command>sudo</command>, <command>run0</command> always spawns shells with login shell
341 semantics, regardless of <option>-i</option>.</para>
342 </refsect1>
343
344 <refsect1>
345 <title>Exit status</title>
346
347 <para>On success, 0 is returned. If <command>run0</command> failed to start the session or the specified command fails, a
348 non-zero return value will be returned.</para>
349 </refsect1>
350
351 <refsect1>
352 <title>Environment Variables</title>
353
354 <para>As with <command>systemd-run</command>, the session will inherit the system
355 environment from the service manager. In addition, the following environment variables will be set:</para>
356
357 <variablelist>
358 <varlistentry>
359 <term><varname>$TERM</varname></term>
360 <listitem><para>Copied from the <varname>$TERM</varname> of the caller. Can be overridden with
361 <option>--setenv=</option></para>
362
363 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
364 </varlistentry>
365
366 <varlistentry>
367 <term><varname>$SUDO_USER</varname></term>
368 <listitem><para>Set to the username of the originating user.</para>
369
370 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
371 </varlistentry>
372
373 <varlistentry>
374 <term><varname>$SUDO_UID</varname></term>
375 <listitem><para>Set to the numeric UNIX user id of the originating user.</para>
376
377 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
378 </varlistentry>
379
380 <varlistentry>
381 <term><varname>$SUDO_GID</varname></term>
382 <listitem><para>Set to the primary numeric UNIX group id of the originating session.</para>
383
384 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
385 </varlistentry>
386
387 <varlistentry>
388 <term><varname>$SHELL_PROMPT_PREFIX</varname></term>
389 <listitem><para>By default, set to the superhero emoji (if supported), but may be overridden with the
390 <varname>$SYSTEMD_RUN_SHELL_PROMPT_PREFIX</varname> environment variable (see below), or the
391 <option>--shell-prompt-prefix=</option> switch (see above).</para>
392
393 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
394 </varlistentry>
395 </variablelist>
396
397 <para>The following variables may be passed to <command>run0</command>:</para>
398
399 <variablelist>
400 <varlistentry>
401 <term><varname>$SYSTEMD_RUN_SHELL_PROMPT_PREFIX</varname></term>
402 <listitem><para>If set, overrides the default shell prompt prefix that <command>run0</command> sets
403 for the invoked shell (the superhero emoji). Set to an empty string to disable shell prompt
404 prefixing.</para>
405
406 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
407 </varlistentry>
408 </variablelist>
409
410 </refsect1>
411
412 <refsect1>
413 <title>See Also</title>
414 <para><simplelist type="inline">
415 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
416 <member><citerefentry><refentrytitle>systemd-run</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
417 <member><citerefentry project='man-pages'><refentrytitle>sudo</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
418 <member><citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
419 <member><citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
420 </simplelist></para>
421 </refsect1>
422
423 </refentry>