]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/pam_systemd.xml
Merge pull request #30990 from poettering/more-mime
[thirdparty/systemd.git] / man / pam_systemd.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
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="pam_systemd" conditional='HAVE_PAM' xmlns:xi="http://www.w3.org/2001/XInclude">
7
8 <refentryinfo>
9 <title>pam_systemd</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>pam_systemd</refentrytitle>
15 <manvolnum>8</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>pam_systemd</refname>
20 <refpurpose>Register user sessions in the systemd login manager</refpurpose>
21 </refnamediv>
22
23 <refsynopsisdiv>
24 <para><filename>pam_systemd.so</filename></para>
25 </refsynopsisdiv>
26
27 <refsect1>
28 <title>Description</title>
29
30 <para><command>pam_systemd</command> registers user sessions with
31 the systemd login manager
32 <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
33 and hence the systemd control group hierarchy.</para>
34
35 <para>The module also applies various resource management and runtime parameters to the new session, as
36 configured in the <ulink url="https://systemd.io/USER_RECORD">JSON User Records</ulink> of the user, when
37 one is defined.</para>
38
39 <para>On login, this module — in conjunction with <filename>systemd-logind.service</filename> — ensures the
40 following:</para>
41
42 <orderedlist>
43 <listitem><para>If it does not exist yet, the user runtime directory <filename>/run/user/$UID</filename> is
44 either created or mounted as new <literal>tmpfs</literal> file system with quota applied, and its ownership
45 changed to the user that is logging in.</para></listitem>
46
47 <listitem><para>The <varname>$XDG_SESSION_ID</varname> environment variable is initialized. If auditing is
48 available and <command>pam_loginuid.so</command> was run before this module (which is highly recommended), the
49 variable is initialized from the auditing session id (<filename>/proc/self/sessionid</filename>). Otherwise, an
50 independent session counter is used.</para></listitem>
51
52 <listitem><para>A new systemd scope unit is created for the session. If this is the first concurrent session of
53 the user, an implicit per-user slice unit below <filename>user.slice</filename> is automatically created and the
54 scope placed into it. An instance of the system service <filename>user@.service</filename>, which runs the
55 systemd user manager instance, is started.</para></listitem>
56
57 <listitem><para>The <literal>$TZ</literal>, <literal>$EMAIL</literal> and <literal>$LANG</literal>
58 environment variables are configured for the user, based on the respective data from the user's JSON
59 record (if it is defined). Moreover, any environment variables explicitly configured in the user record
60 are imported, and the umask, nice level, and resource limits initialized.</para></listitem>
61 </orderedlist>
62
63 <para>On logout, this module ensures the following:</para>
64
65 <orderedlist>
66 <listitem><para>If enabled in
67 <citerefentry><refentrytitle>logind.conf</refentrytitle>
68 <manvolnum>5</manvolnum></citerefentry> (<varname>KillUserProcesses=</varname>), all processes of the session are
69 terminated. If the last concurrent session of a user ends, the user's systemd instance will be terminated too,
70 and so will the user's slice unit.</para></listitem>
71
72 <listitem><para>If the last concurrent session of a user ends,
73 the user runtime directory <filename>/run/user/$UID</filename> and all its
74 contents are removed, too.</para></listitem>
75 </orderedlist>
76
77 <para>If the system was not booted up with systemd as init system,
78 this module does nothing and immediately returns
79 <constant>PAM_SUCCESS</constant>.</para>
80
81 </refsect1>
82
83 <refsect1>
84 <title>Options</title>
85
86 <para>The following options are understood:</para>
87
88 <variablelist class='pam-directives'>
89
90 <varlistentry>
91 <term><varname>class=</varname></term>
92
93 <listitem><para>Takes a string argument which sets the session class. The
94 <varname>XDG_SESSION_CLASS</varname> environment variable (see below) takes precedence. See
95 <citerefentry><refentrytitle>sd_session_get_class</refentrytitle><manvolnum>3</manvolnum></citerefentry>
96 for a way to query the class of a session. The following session classes are defined:</para>
97
98 <table>
99 <title>Session Classes</title>
100 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
101 <colspec colname="name" />
102 <colspec colname="explanation" />
103 <thead>
104 <row>
105 <entry>Name</entry>
106 <entry>Explanation</entry>
107 </row>
108 </thead>
109 <tbody>
110 <row>
111 <entry><constant>user</constant></entry>
112 <entry>A regular interactive user session. This is the default class for sessions for which a TTY or X display is known at session registration time.</entry>
113 </row>
114 <row>
115 <entry><constant>user-early</constant></entry>
116 <entry>Similar to <literal>user</literal> but sessions of this class are not ordered after <filename>systemd-user-sessions.service</filename>, i.e. may be started before regular sessions are allowed to be established. This session class is the default for sessions of the root user that would otherwise qualify for the <constant>user</constant> class, see above. (Added in v256.)</entry>
117 </row>
118 <row>
119 <entry><constant>greeter</constant></entry>
120 <entry>Similar to <literal>user</literal> but for sessions that are spawned by a display manager ephemerally and which prompt the user for login credentials.</entry>
121 </row>
122 <row>
123 <entry><constant>lock-screen</constant></entry>
124 <entry>Similar to <literal>user</literal> but for sessions that are spawned by a display manager ephemerally and which show a lock screen that can be used to unlock locked user accounts or sessions.</entry>
125 </row>
126 <row>
127 <entry><constant>background</constant></entry>
128 <entry>Used for background sessions, such as those invoked by <command>cron</command> and similar tools. This is the default class for sessions for which no TTY or X display is known at session registration time.</entry>
129 </row>
130 <row>
131 <entry><constant>background-light</constant></entry>
132 <entry>Similar to <constant>background</constant>, but sessions of this class will not pull in the <filename>user@.service</filename> of the user, and thus possibly have no services of the user running. (Added in v256.)</entry>
133 </row>
134 <row>
135 <entry><constant>manager</constant></entry>
136 <entry>The <filename>user@.service</filename> service of the user is registered under this session class. (Added in v256.)</entry>
137 </row>
138 <row>
139 <entry><constant>manager-early</constant></entry>
140 <entry>Similar to <constant>manager</constant>, but for the root user. Compare with the <constant>user</constant> vs. <constant>user-early</constant> situation. (Added in v256.)</entry>
141 </row>
142 </tbody>
143 </tgroup>
144 </table>
145
146 <xi:include href="version-info.xml" xpointer="v197"/></listitem>
147 </varlistentry>
148
149 <varlistentry>
150 <term><varname>type=</varname></term>
151
152 <listitem><para>Takes a string argument which sets the session type. The <varname>XDG_SESSION_TYPE</varname>
153 environment variable (see below) takes precedence. One of <literal>unspecified</literal>,
154 <literal>tty</literal>, <literal>x11</literal>, <literal>wayland</literal> or <literal>mir</literal>. See
155 <citerefentry><refentrytitle>sd_session_get_type</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
156 details about the session type.</para>
157
158 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
159 </varlistentry>
160
161 <varlistentry>
162 <term><varname>desktop=</varname></term>
163
164 <listitem><para>Takes a single, short identifier string for the desktop environment. The
165 <varname>XDG_SESSION_DESKTOP</varname> environment variable (see below) takes precedence. This may be used to
166 indicate the session desktop used, where this applies and if this information is available. For example:
167 <literal>GNOME</literal>, or <literal>KDE</literal>. It is recommended to use the same identifiers and
168 capitalization as for <varname>$XDG_CURRENT_DESKTOP</varname>, as defined by the <ulink
169 url="https://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop Entry
170 Specification</ulink>. (However, note that the option only takes a single item, and not a colon-separated list
171 like <varname>$XDG_CURRENT_DESKTOP</varname>.) See
172 <citerefentry><refentrytitle>sd_session_get_desktop</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
173 further details.</para>
174
175 <xi:include href="version-info.xml" xpointer="v240"/></listitem>
176 </varlistentry>
177
178 <varlistentry>
179 <term><varname>default-capability-bounding-set=</varname></term>
180 <term><varname>default-capability-ambient-set=</varname></term>
181
182 <listitem><para>Takes a comma-separated list of process capabilities
183 (e.g. <constant>CAP_WAKE_ALARM</constant>, <constant>CAP_BLOCK_SUSPEND</constant>, …) to set for the
184 invoked session's processes, if the user record does not encode appropriate sets of capabilities
185 directly. See <citerefentry
186 project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>
187 for details on the capabilities concept. If not specified, the default bounding set is left as is
188 (i.e. usually contains the full set of capabilities). The default ambient set is set to
189 <constant>CAP_WAKE_ALARM</constant> for regular users if the PAM session is associated with a local
190 seat or if it is invoked for the <literal>systemd-user</literal> service. Otherwise defaults to the
191 empty set.</para>
192
193 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
194 </varlistentry>
195
196 <varlistentry>
197 <term><varname>debug</varname><optional>=</optional></term>
198
199 <listitem><para>Takes an optional boolean argument. If yes or without the argument, the module will log
200 debugging information as it operates.</para></listitem>
201 </varlistentry>
202 </variablelist>
203 </refsect1>
204
205 <refsect1>
206 <title>Module Types Provided</title>
207
208 <para>Only <option>session</option> is provided.</para>
209 </refsect1>
210
211 <refsect1>
212 <title>Environment</title>
213
214 <para>The following environment variables are initialized by the module and available to the processes of the
215 user's session:</para>
216
217 <variablelist class='environment-variables'>
218 <varlistentry>
219 <term><varname>$XDG_SESSION_ID</varname></term>
220
221 <listitem><para>A short session identifier, suitable to be used in filenames. The string itself should be
222 considered opaque, although often it is just the audit session ID as reported by
223 <filename>/proc/self/sessionid</filename>. Each ID will be assigned only once during machine uptime. It may
224 hence be used to uniquely label files or other resources of this session. Combine this ID with the boot
225 identifier, as returned by
226 <citerefentry><refentrytitle>sd_id128_get_boot</refentrytitle><manvolnum>3</manvolnum></citerefentry>, for a
227 globally unique identifier.</para></listitem>
228 </varlistentry>
229
230 <varlistentry>
231 <term><varname>$XDG_RUNTIME_DIR</varname></term>
232
233 <listitem><para>Path to a user-private user-writable directory
234 that is bound to the user login time on the machine. It is
235 automatically created the first time a user logs in and
236 removed on the user's final logout. If a user logs in twice at
237 the same time, both sessions will see the same
238 <varname>$XDG_RUNTIME_DIR</varname> and the same contents. If
239 a user logs in once, then logs out again, and logs in again,
240 the directory contents will have been lost in between, but
241 applications should not rely on this behavior and must be able
242 to deal with stale files. To store session-private data in
243 this directory, the user should include the value of
244 <varname>$XDG_SESSION_ID</varname> in the filename. This
245 directory shall be used for runtime file system objects such
246 as <constant>AF_UNIX</constant> sockets, FIFOs, PID files and
247 similar. It is guaranteed that this directory is local and
248 offers the greatest possible file system feature set the
249 operating system provides. For further details, see the <ulink
250 url="https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
251 Base Directory Specification</ulink>. <varname>$XDG_RUNTIME_DIR</varname>
252 is not set if the current user is not the original user of the session.</para></listitem>
253 </varlistentry>
254
255 <varlistentry>
256 <term><varname>$TZ</varname></term>
257 <term><varname>$EMAIL</varname></term>
258 <term><varname>$LANG</varname></term>
259
260 <listitem><para>If a JSON user record is known for the user logging in these variables are
261 initialized from the respective data in the record.</para>
262
263 <xi:include href="version-info.xml" xpointer="v245"/></listitem>
264 </varlistentry>
265
266 </variablelist>
267
268 <para>The following environment variables are read by the module and may be used by the PAM service to pass
269 metadata to the module. If these variables are not set when the PAM module is invoked but can be determined
270 otherwise they are set by the module, so that these variables are initialized for the session and applications if
271 known at all.</para>
272
273 <variablelist class='environment-variables'>
274 <varlistentry>
275 <term><varname>$XDG_SESSION_TYPE</varname></term>
276
277 <listitem><para>The session type. This may be used instead of <varname>type=</varname> on the module parameter
278 line, and is usually preferred.</para>
279
280 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
281 </varlistentry>
282
283 <varlistentry>
284 <term><varname>$XDG_SESSION_CLASS</varname></term>
285
286 <listitem><para>The session class. This may be used instead of <varname>class=</varname> on the module parameter
287 line, and is usually preferred.</para>
288
289 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
290 </varlistentry>
291
292 <varlistentry>
293 <term><varname>$XDG_SESSION_DESKTOP</varname></term>
294
295 <listitem><para>The desktop identifier. This may be used instead of <varname>desktop=</varname> on the module
296 parameter line, and is usually preferred.</para>
297
298 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
299 </varlistentry>
300
301 <varlistentry>
302 <term><varname>$XDG_SEAT</varname></term>
303
304 <listitem><para>The seat name the session shall be registered
305 for, if any.</para>
306
307 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
308 </varlistentry>
309
310 <varlistentry>
311 <term><varname>$XDG_VTNR</varname></term>
312
313 <listitem><para>The VT number the session shall be registered
314 for, if any. (Only applies to seats with a VT available, such
315 as <literal>seat0</literal>)</para>
316
317 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
318 </varlistentry>
319 </variablelist>
320
321 <para>If not set, <command>pam_systemd</command> will initialize
322 <varname>$XDG_SEAT</varname> and <varname>$XDG_VTNR</varname>
323 based on the <varname>$DISPLAY</varname> variable (if the latter is set).</para>
324 </refsect1>
325
326 <refsect1>
327 <title>Session limits</title>
328
329 <para>PAM modules earlier in the stack, that is those that come before <command>pam_systemd.so</command>,
330 can set session scope limits using the PAM context objects. The data for these objects is provided as <constant>NUL</constant>-terminated C strings
331 and maps directly to the respective unit resource control directives. Note that these limits apply to individual sessions of the user,
332 they do not apply to all user processes as a combined whole. In particular, the per-user <command>user@.service</command> unit instance,
333 which runs the <command>systemd --user</command> manager process and its children, and is tracked outside of any session, being shared
334 by all the user's sessions, is not covered by these limits.
335 </para>
336
337 <para> See
338 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information about the resources.
339 Also, see <citerefentry project='man-pages'><refentrytitle>pam_set_data</refentrytitle><manvolnum>3</manvolnum></citerefentry> for additional information about how to set
340 the context objects.
341 </para>
342
343 <variablelist class='pam-directives'>
344 <varlistentry>
345 <term><varname>systemd.memory_max=</varname></term>
346
347 <listitem><para>Sets unit <varname>MemoryMax=</varname>.</para>
348
349 <xi:include href="version-info.xml" xpointer="v239"/></listitem>
350 </varlistentry>
351
352 <varlistentry>
353 <term><varname>systemd.tasks_max=</varname></term>
354
355 <listitem><para>Sets unit <varname>TasksMax=</varname>.</para>
356
357 <xi:include href="version-info.xml" xpointer="v239"/></listitem>
358 </varlistentry>
359
360 <varlistentry>
361 <term><varname>systemd.cpu_weight=</varname></term>
362
363 <listitem><para>Sets unit <varname>CPUWeight=</varname>.</para>
364
365 <xi:include href="version-info.xml" xpointer="v239"/></listitem>
366 </varlistentry>
367
368 <varlistentry>
369 <term><varname>systemd.io_weight=</varname></term>
370
371 <listitem><para>Sets unit <varname>IOWeight=</varname>.</para>
372
373 <xi:include href="version-info.xml" xpointer="v239"/></listitem>
374 </varlistentry>
375
376 <varlistentry>
377 <term><varname>systemd.runtime_max_sec=</varname></term>
378
379 <listitem><para>Sets unit <varname>RuntimeMaxSec=</varname>.</para>
380
381 <xi:include href="version-info.xml" xpointer="v244"/></listitem>
382 </varlistentry>
383 </variablelist>
384
385 <para>Example data as can be provided from an another PAM module:
386 <programlisting>
387 pam_set_data(handle, "systemd.memory_max", (void *)"200M", cleanup);
388 pam_set_data(handle, "systemd.tasks_max", (void *)"50", cleanup);
389 pam_set_data(handle, "systemd.cpu_weight", (void *)"100", cleanup);
390 pam_set_data(handle, "systemd.io_weight", (void *)"340", cleanup);
391 pam_set_data(handle, "systemd.runtime_max_sec", (void *)"3600", cleanup);
392 </programlisting>
393 </para>
394
395 </refsect1>
396
397 <refsect1>
398 <title>Example</title>
399
400 <para>Here's an example PAM configuration fragment that allows users sessions to be managed by
401 <filename>systemd-logind.service</filename>:</para>
402
403 <programlisting>#%PAM-1.0
404 auth sufficient pam_unix.so
405 -auth sufficient pam_systemd_home.so
406 auth required pam_deny.so
407
408 account required pam_nologin.so
409 -account sufficient pam_systemd_home.so
410 account sufficient pam_unix.so
411 account required pam_permit.so
412
413 -password sufficient pam_systemd_home.so
414 password sufficient pam_unix.so sha512 shadow try_first_pass
415 password required pam_deny.so
416
417 -session optional pam_keyinit.so revoke
418 -session optional pam_loginuid.so
419 -session optional pam_systemd_home.so
420 <command>-session optional pam_systemd.so</command>
421 session required pam_unix.so</programlisting>
422 </refsect1>
423
424 <refsect1>
425 <title>See Also</title>
426 <para><simplelist type="inline">
427 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
428 <member><citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
429 <member><citerefentry><refentrytitle>logind.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
430 <member><citerefentry><refentrytitle>loginctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
431 <member><citerefentry><refentrytitle>pam_systemd_home</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
432 <member><citerefentry project='man-pages'><refentrytitle>pam.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
433 <member><citerefentry project='man-pages'><refentrytitle>pam.d</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
434 <member><citerefentry project='man-pages'><refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
435 <member><citerefentry project='man-pages'><refentrytitle>pam_loginuid</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
436 <member><citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
437 <member><citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
438 <member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
439 </simplelist></para>
440 </refsect1>
441
442 </refentry>