]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/pam_systemd.xml
man: clarify that LogNamespace= is for system services only
[thirdparty/systemd.git] / man / pam_systemd.xml
CommitLineData
160cd5c9 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0307f791 4<!-- SPDX-License-Identifier: LGPL-2.1+ -->
160cd5c9 5
47c49034 6<refentry id="pam_systemd" conditional='HAVE_PAM'>
160cd5c9 7
798d3a52
ZJS
8 <refentryinfo>
9 <title>pam_systemd</title>
10 <productname>systemd</productname>
798d3a52
ZJS
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
fc89f88e
LP
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 Record</ulink> of the user, when
37 one is defined.</para>
38
66a5b902
LP
39 <para>On login, this module — in conjunction with <filename>systemd-logind.service</filename> — ensures the
40 following:</para>
798d3a52
ZJS
41
42 <orderedlist>
66a5b902
LP
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
798d3a52
ZJS
50 independent session counter is used.</para></listitem>
51
66a5b902
LP
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
fc89f88e
LP
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>
798d3a52
ZJS
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>
66a5b902
LP
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>
798d3a52
ZJS
71
72 <listitem><para>If the last concurrent session of a user ends,
5c50321c 73 the user runtime directory <filename>/run/user/$UID</filename> and all its
798d3a52
ZJS
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>
2691d65c 91 <term><varname>class=</varname></term>
798d3a52 92
b115f33c
LP
93 <listitem><para>Takes a string argument which sets the session class. The <varname>XDG_SESSION_CLASS</varname>
94 environment variable (see below) takes precedence. One of <literal>user</literal>, <literal>greeter</literal>,
95 <literal>lock-screen</literal> or <literal>background</literal>. See
96 <citerefentry><refentrytitle>sd_session_get_class</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
97 details about the session class.</para></listitem>
798d3a52
ZJS
98 </varlistentry>
99
100 <varlistentry>
2691d65c 101 <term><varname>type=</varname></term>
798d3a52 102
b115f33c
LP
103 <listitem><para>Takes a string argument which sets the session type. The <varname>XDG_SESSION_TYPE</varname>
104 environment variable (see below) takes precedence. One of <literal>unspecified</literal>,
105 <literal>tty</literal>, <literal>x11</literal>, <literal>wayland</literal> or <literal>mir</literal>. See
106 <citerefentry><refentrytitle>sd_session_get_type</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
107 details about the session type.</para></listitem>
108 </varlistentry>
109
110 <varlistentry>
2691d65c 111 <term><varname>desktop=</varname></term>
b115f33c
LP
112
113 <listitem><para>Takes a single, short identifier string for the desktop environment. The
114 <varname>XDG_SESSION_DESKTOP</varname> environment variable (see below) takes precedence. This may be used to
115 indicate the session desktop used, where this applies and if this information is available. For example:
116 <literal>GNOME</literal>, or <literal>KDE</literal>. It is recommended to use the same identifiers and
117 capitalization as for <varname>$XDG_CURRENT_DESKTOP</varname>, as defined by the <ulink
118 url="http://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop Entry
119 Specification</ulink>. (However, note that the option only takes a single item, and not a colon-separated list
120 like <varname>$XDG_CURRENT_DESKTOP</varname>.) See
121 <citerefentry><refentrytitle>sd_session_get_desktop</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
122 further details.</para></listitem>
798d3a52
ZJS
123 </varlistentry>
124
125 <varlistentry>
2691d65c 126 <term><varname>debug</varname><optional>=</optional></term>
798d3a52 127
b115f33c
LP
128 <listitem><para>Takes an optional boolean argument. If yes or without the argument, the module will log
129 debugging information as it operates.</para></listitem>
798d3a52
ZJS
130 </varlistentry>
131 </variablelist>
132 </refsect1>
133
134 <refsect1>
135 <title>Module Types Provided</title>
136
137 <para>Only <option>session</option> is provided.</para>
138 </refsect1>
139
140 <refsect1>
141 <title>Environment</title>
142
b115f33c
LP
143 <para>The following environment variables are initialized by the module and available to the processes of the
144 user's session:</para>
798d3a52
ZJS
145
146 <variablelist class='environment-variables'>
147 <varlistentry>
148 <term><varname>$XDG_SESSION_ID</varname></term>
149
b115f33c
LP
150 <listitem><para>A short session identifier, suitable to be used in filenames. The string itself should be
151 considered opaque, although often it is just the audit session ID as reported by
152 <filename>/proc/self/sessionid</filename>. Each ID will be assigned only once during machine uptime. It may
153 hence be used to uniquely label files or other resources of this session. Combine this ID with the boot
154 identifier, as returned by
155 <citerefentry><refentrytitle>sd_id128_get_boot</refentrytitle><manvolnum>3</manvolnum></citerefentry>, for a
e9dd6984 156 globally unique identifier.</para></listitem>
798d3a52
ZJS
157 </varlistentry>
158
159 <varlistentry>
160 <term><varname>$XDG_RUNTIME_DIR</varname></term>
161
162 <listitem><para>Path to a user-private user-writable directory
163 that is bound to the user login time on the machine. It is
164 automatically created the first time a user logs in and
165 removed on the user's final logout. If a user logs in twice at
166 the same time, both sessions will see the same
167 <varname>$XDG_RUNTIME_DIR</varname> and the same contents. If
168 a user logs in once, then logs out again, and logs in again,
169 the directory contents will have been lost in between, but
170 applications should not rely on this behavior and must be able
171 to deal with stale files. To store session-private data in
172 this directory, the user should include the value of
173 <varname>$XDG_SESSION_ID</varname> in the filename. This
174 directory shall be used for runtime file system objects such
175 as <constant>AF_UNIX</constant> sockets, FIFOs, PID files and
176 similar. It is guaranteed that this directory is local and
177 offers the greatest possible file system feature set the
b938cb90 178 operating system provides. For further details, see the <ulink
798d3a52 179 url="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
5c50321c
AHL
180 Base Directory Specification</ulink>. <varname>$XDG_RUNTIME_DIR</varname>
181 is not set if the current user is not the original user of the session.</para></listitem>
798d3a52
ZJS
182 </varlistentry>
183
fc89f88e
LP
184 <varlistentry>
185 <term><varname>$TZ</varname></term>
186 <term><varname>$EMAIL</varname></term>
187 <term><varname>$LANG</varname></term>
188
189 <listitem><para>If a JSON user record is known for the user logging in these variables are
190 initialized from the respective data in the record.</para></listitem>
191 </varlistentry>
192
798d3a52
ZJS
193 </variablelist>
194
b115f33c
LP
195 <para>The following environment variables are read by the module and may be used by the PAM service to pass
196 metadata to the module. If these variables are not set when the PAM module is invoked but can be determined
197 otherwise they are set by the module, so that these variables are initialized for the session and applications if
198 known at all.</para>
798d3a52
ZJS
199
200 <variablelist class='environment-variables'>
201 <varlistentry>
202 <term><varname>$XDG_SESSION_TYPE</varname></term>
203
98647fa0 204 <listitem><para>The session type. This may be used instead of <varname>type=</varname> on the module parameter
b115f33c 205 line, and is usually preferred.</para></listitem>
798d3a52
ZJS
206 </varlistentry>
207
208 <varlistentry>
209 <term><varname>$XDG_SESSION_CLASS</varname></term>
210
2691d65c 211 <listitem><para>The session class. This may be used instead of <varname>class=</varname> on the module parameter
b115f33c 212 line, and is usually preferred.</para></listitem>
798d3a52
ZJS
213 </varlistentry>
214
215 <varlistentry>
216 <term><varname>$XDG_SESSION_DESKTOP</varname></term>
217
2691d65c 218 <listitem><para>The desktop identifier. This may be used instead of <varname>desktop=</varname> on the module
b115f33c 219 parameter line, and is usually preferred.</para></listitem>
798d3a52
ZJS
220 </varlistentry>
221
222 <varlistentry>
223 <term><varname>$XDG_SEAT</varname></term>
224
225 <listitem><para>The seat name the session shall be registered
226 for, if any.</para></listitem>
227 </varlistentry>
228
229 <varlistentry>
230 <term><varname>$XDG_VTNR</varname></term>
231
232 <listitem><para>The VT number the session shall be registered
233 for, if any. (Only applies to seats with a VT available, such
234 as <literal>seat0</literal>)</para></listitem>
235 </varlistentry>
798d3a52 236 </variablelist>
2230a290 237
1acfbbff
LP
238 <para>If not set, <command>pam_systemd</command> will initialize
239 <varname>$XDG_SEAT</varname> and <varname>$XDG_VTNR</varname>
240 based on the <varname>$DISPLAY</varname> variable (if the latter is set).</para>
798d3a52
ZJS
241 </refsect1>
242
22f93314
JS
243 <refsect1>
244 <title>Session limits</title>
245
246 <para>PAM modules earlier in the stack, that is those that come before <command>pam_systemd.so</command>,
247 can set session scope limits using the PAM context objects. The data for these objects is provided as NUL-terminated C strings
248 and maps directly to the respective unit resource control directives. Note that these limits apply to individual sessions of the user,
249 they do not apply to all user processes as a combined whole. In particular, the per-user <command>user@.service</command> unit instance,
250 which runs the <command>systemd --user</command> manager process and its children, and is tracked outside of any session, being shared
251 by all the user's sessions, is not covered by these limits.
252 </para>
253
254 <para> See
255 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information about the resources.
b7a47345 256 Also, see <citerefentry project='man-pages'><refentrytitle>pam_set_data</refentrytitle><manvolnum>3</manvolnum></citerefentry> for additional information about how to set
22f93314
JS
257 the context objects.
258 </para>
259
2691d65c 260 <variablelist class='pam-directives'>
22f93314 261 <varlistentry>
1f63c72d 262 <term><varname>systemd.memory_max=</varname></term>
22f93314
JS
263
264 <listitem><para>Sets unit <varname>MemoryMax=</varname>.</para></listitem>
265 </varlistentry>
266
267 <varlistentry>
1f63c72d 268 <term><varname>systemd.tasks_max=</varname></term>
22f93314
JS
269
270 <listitem><para>Sets unit <varname>TasksMax=</varname>.</para></listitem>
271 </varlistentry>
272
273 <varlistentry>
1f63c72d 274 <term><varname>systemd.cpu_weight=</varname></term>
22f93314
JS
275
276 <listitem><para>Sets unit <varname>CPUWeight=</varname>.</para></listitem>
277 </varlistentry>
278
279 <varlistentry>
1f63c72d 280 <term><varname>systemd.io_weight=</varname></term>
22f93314
JS
281
282 <listitem><para>Sets unit <varname>IOWeight=</varname>.</para></listitem>
283 </varlistentry>
adc09af2
PW
284
285 <varlistentry>
1f63c72d 286 <term><varname>systemd.runtime_max_sec=</varname></term>
adc09af2
PW
287
288 <listitem><para>Sets unit <varname>RuntimeMaxSec=</varname>.</para></listitem>
289 </varlistentry>
22f93314
JS
290 </variablelist>
291
292 <para>Example data as can be provided from an another PAM module:
293 <programlisting>
294pam_set_data(handle, "systemd.memory_max", (void *)"200M", cleanup);
295pam_set_data(handle, "systemd.tasks_max", (void *)"50", cleanup);
296pam_set_data(handle, "systemd.cpu_weight", (void *)"100", cleanup);
297pam_set_data(handle, "systemd.io_weight", (void *)"340", cleanup);
adc09af2 298pam_set_data(handle, "systemd.runtime_max_sec", (void *)"3600", cleanup);
22f93314
JS
299 </programlisting>
300 </para>
301
302 </refsect1>
303
798d3a52
ZJS
304 <refsect1>
305 <title>Example</title>
306
fc89f88e
LP
307 <para>Here's an example PAM configuration fragment that allows users sessions to be managed by
308 <filename>systemd-logind.service</filename>:</para>
309
798d3a52 310 <programlisting>#%PAM-1.0
4ad5bf78
LP
311auth sufficient pam_unix.so
312-auth sufficient pam_systemd_home.so
313auth required pam_deny.so
314
315account required pam_nologin.so
316-account sufficient pam_systemd_home.so
317account sufficient pam_unix.so
318account required pam_permit.so
319
320-password sufficient pam_systemd_home.so
321password sufficient pam_unix.so sha512 shadow try_first_pass try_authtok
322password required pam_deny.so
323
324-session optional pam_keyinit.so revoke
325-session optional pam_loginuid.so
326-session optional pam_systemd_home.so
327<command>-session optional pam_systemd.so</command>
328session required pam_unix.so</programlisting>
798d3a52
ZJS
329 </refsect1>
330
331 <refsect1>
332 <title>See Also</title>
333 <para>
334 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
335 <citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
336 <citerefentry><refentrytitle>logind.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
337 <citerefentry><refentrytitle>loginctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
fc89f88e 338 <citerefentry><refentrytitle>pam_systemd_home</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
798d3a52
ZJS
339 <citerefentry project='man-pages'><refentrytitle>pam.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
340 <citerefentry project='man-pages'><refentrytitle>pam.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
341 <citerefentry project='man-pages'><refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
342 <citerefentry project='man-pages'><refentrytitle>pam_loginuid</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
343 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
344 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
345 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
346 </para>
347 </refsect1>
160cd5c9
LP
348
349</refentry>