1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
8 Copyright 2010 Lennart Poettering
11 <refentry id=
"pam_systemd" conditional='HAVE_PAM'
>
14 <title>pam_systemd
</title>
15 <productname>systemd
</productname>
19 <contrib>Developer
</contrib>
20 <firstname>Lennart
</firstname>
21 <surname>Poettering
</surname>
22 <email>lennart@poettering.net
</email>
28 <refentrytitle>pam_systemd
</refentrytitle>
29 <manvolnum>8</manvolnum>
33 <refname>pam_systemd
</refname>
34 <refpurpose>Register user sessions in the systemd login manager
</refpurpose>
38 <para><filename>pam_systemd.so
</filename></para>
42 <title>Description
</title>
44 <para><command>pam_systemd
</command> registers user sessions with
45 the systemd login manager
46 <citerefentry><refentrytitle>systemd-logind.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
47 and hence the systemd control group hierarchy.
</para>
49 <para>On login, this module — in conjunction with
<filename>systemd-logind.service
</filename> — ensures the
53 <listitem><para>If it does not exist yet, the user runtime directory
<filename>/run/user/$UID
</filename> is
54 either created or mounted as new
<literal>tmpfs
</literal> file system with quota applied, and its ownership
55 changed to the user that is logging in.
</para></listitem>
57 <listitem><para>The
<varname>$XDG_SESSION_ID
</varname> environment variable is initialized. If auditing is
58 available and
<command>pam_loginuid.so
</command> was run before this module (which is highly recommended), the
59 variable is initialized from the auditing session id (
<filename>/proc/self/sessionid
</filename>). Otherwise, an
60 independent session counter is used.
</para></listitem>
62 <listitem><para>A new systemd scope unit is created for the session. If this is the first concurrent session of
63 the user, an implicit per-user slice unit below
<filename>user.slice
</filename> is automatically created and the
64 scope placed into it. An instance of the system service
<filename>user@.service
</filename>, which runs the
65 systemd user manager instance, is started.
</para></listitem>
68 <para>On logout, this module ensures the following:
</para>
71 <listitem><para>If enabled in
72 <citerefentry><refentrytitle>logind.conf
</refentrytitle>
73 <manvolnum>5</manvolnum></citerefentry> (
<varname>KillUserProcesses=
</varname>), all processes of the session are
74 terminated. If the last concurrent session of a user ends, the user's systemd instance will be terminated too,
75 and so will the user's slice unit.
</para></listitem>
77 <listitem><para>If the last concurrent session of a user ends,
78 the user runtime directory
<filename>/run/user/$UID
</filename> and all its
79 contents are removed, too.
</para></listitem>
82 <para>If the system was not booted up with systemd as init system,
83 this module does nothing and immediately returns
84 <constant>PAM_SUCCESS
</constant>.
</para>
89 <title>Options
</title>
91 <para>The following options are understood:
</para>
93 <variablelist class='pam-directives'
>
96 <term><option>class=
</option></term>
98 <listitem><para>Takes a string argument which sets the session
99 class. The XDG_SESSION_CLASS environmental variable takes
101 <literal>user
</literal>,
102 <literal>greeter
</literal>,
103 <literal>lock-screen
</literal> or
104 <literal>background
</literal>. See
105 <citerefentry><refentrytitle>sd_session_get_class
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
106 for details about the session class.
</para></listitem>
110 <term><option>type=
</option></term>
112 <listitem><para>Takes a string argument which sets the session
113 type. The XDG_SESSION_TYPE environmental variable takes
115 <literal>unspecified
</literal>,
116 <literal>tty
</literal>,
117 <literal>x11
</literal>,
118 <literal>wayland
</literal> or
119 <literal>mir
</literal>. See
120 <citerefentry><refentrytitle>sd_session_get_type
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
121 for details about the session type.
</para></listitem>
125 <term><option>debug
<optional>=
</optional></option></term>
127 <listitem><para>Takes an optional
128 boolean argument. If yes or without
129 the argument, the module will log
130 debugging information as it
131 operates.
</para></listitem>
137 <title>Module Types Provided
</title>
139 <para>Only
<option>session
</option> is provided.
</para>
143 <title>Environment
</title>
145 <para>The following environment variables are set for the
146 processes of the user's session:
</para>
148 <variablelist class='environment-variables'
>
150 <term><varname>$XDG_SESSION_ID
</varname></term>
152 <listitem><para>A session identifier, suitable to be used in
153 filenames. The string itself should be considered opaque,
154 although often it is just the audit session ID as reported by
155 <filename>/proc/self/sessionid
</filename>. Each ID will be
156 assigned only once during machine uptime. It may hence be used
157 to uniquely label files or other resources of this
158 session.
</para></listitem>
162 <term><varname>$XDG_RUNTIME_DIR
</varname></term>
164 <listitem><para>Path to a user-private user-writable directory
165 that is bound to the user login time on the machine. It is
166 automatically created the first time a user logs in and
167 removed on the user's final logout. If a user logs in twice at
168 the same time, both sessions will see the same
169 <varname>$XDG_RUNTIME_DIR
</varname> and the same contents. If
170 a user logs in once, then logs out again, and logs in again,
171 the directory contents will have been lost in between, but
172 applications should not rely on this behavior and must be able
173 to deal with stale files. To store session-private data in
174 this directory, the user should include the value of
175 <varname>$XDG_SESSION_ID
</varname> in the filename. This
176 directory shall be used for runtime file system objects such
177 as
<constant>AF_UNIX
</constant> sockets, FIFOs, PID files and
178 similar. It is guaranteed that this directory is local and
179 offers the greatest possible file system feature set the
180 operating system provides. For further details, see the
<ulink
181 url=
"http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
182 Base Directory Specification
</ulink>.
<varname>$XDG_RUNTIME_DIR
</varname>
183 is not set if the current user is not the original user of the session.
</para></listitem>
188 <para>The following environment variables are read by the module
189 and may be used by the PAM service to pass metadata to the
192 <variablelist class='environment-variables'
>
194 <term><varname>$XDG_SESSION_TYPE
</varname></term>
196 <listitem><para>The session type. This may be used instead of
197 <option>session=
</option> on the module parameter line, and is
198 usually preferred.
</para></listitem>
202 <term><varname>$XDG_SESSION_CLASS
</varname></term>
204 <listitem><para>The session class. This may be used instead of
205 <option>class=
</option> on the module parameter line, and is
206 usually preferred.
</para></listitem>
210 <term><varname>$XDG_SESSION_DESKTOP
</varname></term>
212 <listitem><para>A single, short identifier string for the
213 desktop environment. This may be used to indicate the session
214 desktop used, where this applies and if this information is
215 available. For example:
<literal>GNOME
</literal>, or
216 <literal>KDE
</literal>. It is recommended to use the same
217 identifiers and capitalization as for
218 <varname>$XDG_CURRENT_DESKTOP
</varname>, as defined by the
220 url=
"http://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop
221 Entry Specification
</ulink>. (However, note that
222 <varname>$XDG_SESSION_DESKTOP
</varname> only takes a single
223 item, and not a colon-separated list like
224 <varname>$XDG_CURRENT_DESKTOP
</varname>.) See
225 <citerefentry><refentrytitle>sd_session_get_desktop
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
226 for more details.
</para></listitem>
230 <term><varname>$XDG_SEAT
</varname></term>
232 <listitem><para>The seat name the session shall be registered
233 for, if any.
</para></listitem>
237 <term><varname>$XDG_VTNR
</varname></term>
239 <listitem><para>The VT number the session shall be registered
240 for, if any. (Only applies to seats with a VT available, such
241 as
<literal>seat0
</literal>)
</para></listitem>
245 <para>If not set,
<command>pam_systemd
</command> will determine the
246 values for
<varname>$XDG_SEAT
</varname> and
<varname>$XDG_VTNR
</varname>
247 based on the
<varname>$DISPLAY
</varname> variable.
</para>
251 <title>Session limits
</title>
253 <para>PAM modules earlier in the stack, that is those that come before
<command>pam_systemd.so
</command>,
254 can set session scope limits using the PAM context objects. The data for these objects is provided as NUL-terminated C strings
255 and maps directly to the respective unit resource control directives. Note that these limits apply to individual sessions of the user,
256 they do not apply to all user processes as a combined whole. In particular, the per-user
<command>user@.service
</command> unit instance,
257 which runs the
<command>systemd --user
</command> manager process and its children, and is tracked outside of any session, being shared
258 by all the user's sessions, is not covered by these limits.
262 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information about the resources.
263 Also, see
<citerefentry><refentrytitle>pam_set_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry> for additional information about how to set
269 <term><varname>systemd.memory_max
</varname></term>
271 <listitem><para>Sets unit
<varname>MemoryMax=
</varname>.
</para></listitem>
275 <term><varname>systemd.tasks_max
</varname></term>
277 <listitem><para>Sets unit
<varname>TasksMax=
</varname>.
</para></listitem>
281 <term><varname>systemd.cpu_weight
</varname></term>
283 <listitem><para>Sets unit
<varname>CPUWeight=
</varname>.
</para></listitem>
287 <term><varname>systemd.io_weight
</varname></term>
289 <listitem><para>Sets unit
<varname>IOWeight=
</varname>.
</para></listitem>
293 <para>Example data as can be provided from an another PAM module:
295 pam_set_data(handle,
"systemd.memory_max", (void *)
"200M", cleanup);
296 pam_set_data(handle,
"systemd.tasks_max", (void *)
"50", cleanup);
297 pam_set_data(handle,
"systemd.cpu_weight", (void *)
"100", cleanup);
298 pam_set_data(handle,
"systemd.io_weight", (void *)
"340", cleanup);
305 <title>Example
</title>
307 <programlisting>#%PAM-
1.0
308 auth required pam_unix.so
309 auth required pam_nologin.so
310 account required pam_unix.so
311 password required pam_unix.so
312 session required pam_unix.so
313 session required pam_loginuid.so
314 session required pam_systemd.so
</programlisting>
318 <title>See Also
</title>
320 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
321 <citerefentry><refentrytitle>systemd-logind.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
322 <citerefentry><refentrytitle>logind.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
323 <citerefentry><refentrytitle>loginctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
324 <citerefentry project='man-pages'
><refentrytitle>pam.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
325 <citerefentry project='man-pages'
><refentrytitle>pam.d
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
326 <citerefentry project='man-pages'
><refentrytitle>pam
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
327 <citerefentry project='man-pages'
><refentrytitle>pam_loginuid
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
328 <citerefentry><refentrytitle>systemd.scope
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
329 <citerefentry><refentrytitle>systemd.slice
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
330 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>