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+
9 <refentry id=
"pam_systemd" conditional='HAVE_PAM'
>
12 <title>pam_systemd
</title>
13 <productname>systemd
</productname>
17 <contrib>Developer
</contrib>
18 <firstname>Lennart
</firstname>
19 <surname>Poettering
</surname>
20 <email>lennart@poettering.net
</email>
26 <refentrytitle>pam_systemd
</refentrytitle>
27 <manvolnum>8</manvolnum>
31 <refname>pam_systemd
</refname>
32 <refpurpose>Register user sessions in the systemd login manager
</refpurpose>
36 <para><filename>pam_systemd.so
</filename></para>
40 <title>Description
</title>
42 <para><command>pam_systemd
</command> registers user sessions with
43 the systemd login manager
44 <citerefentry><refentrytitle>systemd-logind.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
45 and hence the systemd control group hierarchy.
</para>
47 <para>On login, this module — in conjunction with
<filename>systemd-logind.service
</filename> — ensures the
51 <listitem><para>If it does not exist yet, the user runtime directory
<filename>/run/user/$UID
</filename> is
52 either created or mounted as new
<literal>tmpfs
</literal> file system with quota applied, and its ownership
53 changed to the user that is logging in.
</para></listitem>
55 <listitem><para>The
<varname>$XDG_SESSION_ID
</varname> environment variable is initialized. If auditing is
56 available and
<command>pam_loginuid.so
</command> was run before this module (which is highly recommended), the
57 variable is initialized from the auditing session id (
<filename>/proc/self/sessionid
</filename>). Otherwise, an
58 independent session counter is used.
</para></listitem>
60 <listitem><para>A new systemd scope unit is created for the session. If this is the first concurrent session of
61 the user, an implicit per-user slice unit below
<filename>user.slice
</filename> is automatically created and the
62 scope placed into it. An instance of the system service
<filename>user@.service
</filename>, which runs the
63 systemd user manager instance, is started.
</para></listitem>
66 <para>On logout, this module ensures the following:
</para>
69 <listitem><para>If enabled in
70 <citerefentry><refentrytitle>logind.conf
</refentrytitle>
71 <manvolnum>5</manvolnum></citerefentry> (
<varname>KillUserProcesses=
</varname>), all processes of the session are
72 terminated. If the last concurrent session of a user ends, the user's systemd instance will be terminated too,
73 and so will the user's slice unit.
</para></listitem>
75 <listitem><para>If the last concurrent session of a user ends,
76 the user runtime directory
<filename>/run/user/$UID
</filename> and all its
77 contents are removed, too.
</para></listitem>
80 <para>If the system was not booted up with systemd as init system,
81 this module does nothing and immediately returns
82 <constant>PAM_SUCCESS
</constant>.
</para>
87 <title>Options
</title>
89 <para>The following options are understood:
</para>
91 <variablelist class='pam-directives'
>
94 <term><option>class=
</option></term>
96 <listitem><para>Takes a string argument which sets the session
97 class. The XDG_SESSION_CLASS environmental variable takes
99 <literal>user
</literal>,
100 <literal>greeter
</literal>,
101 <literal>lock-screen
</literal> or
102 <literal>background
</literal>. See
103 <citerefentry><refentrytitle>sd_session_get_class
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
104 for details about the session class.
</para></listitem>
108 <term><option>type=
</option></term>
110 <listitem><para>Takes a string argument which sets the session
111 type. The XDG_SESSION_TYPE environmental variable takes
113 <literal>unspecified
</literal>,
114 <literal>tty
</literal>,
115 <literal>x11
</literal>,
116 <literal>wayland
</literal> or
117 <literal>mir
</literal>. See
118 <citerefentry><refentrytitle>sd_session_get_type
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
119 for details about the session type.
</para></listitem>
123 <term><option>debug
<optional>=
</optional></option></term>
125 <listitem><para>Takes an optional
126 boolean argument. If yes or without
127 the argument, the module will log
128 debugging information as it
129 operates.
</para></listitem>
135 <title>Module Types Provided
</title>
137 <para>Only
<option>session
</option> is provided.
</para>
141 <title>Environment
</title>
143 <para>The following environment variables are set for the
144 processes of the user's session:
</para>
146 <variablelist class='environment-variables'
>
148 <term><varname>$XDG_SESSION_ID
</varname></term>
150 <listitem><para>A session identifier, suitable to be used in
151 filenames. The string itself should be considered opaque,
152 although often it is just the audit session ID as reported by
153 <filename>/proc/self/sessionid
</filename>. Each ID will be
154 assigned only once during machine uptime. It may hence be used
155 to uniquely label files or other resources of this
156 session.
</para></listitem>
160 <term><varname>$XDG_RUNTIME_DIR
</varname></term>
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
178 operating system provides. For further details, see the
<ulink
179 url=
"http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
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>
186 <para>The following environment variables are read by the module
187 and may be used by the PAM service to pass metadata to the
190 <variablelist class='environment-variables'
>
192 <term><varname>$XDG_SESSION_TYPE
</varname></term>
194 <listitem><para>The session type. This may be used instead of
195 <option>session=
</option> on the module parameter line, and is
196 usually preferred.
</para></listitem>
200 <term><varname>$XDG_SESSION_CLASS
</varname></term>
202 <listitem><para>The session class. This may be used instead of
203 <option>class=
</option> on the module parameter line, and is
204 usually preferred.
</para></listitem>
208 <term><varname>$XDG_SESSION_DESKTOP
</varname></term>
210 <listitem><para>A single, short identifier string for the
211 desktop environment. This may be used to indicate the session
212 desktop used, where this applies and if this information is
213 available. For example:
<literal>GNOME
</literal>, or
214 <literal>KDE
</literal>. It is recommended to use the same
215 identifiers and capitalization as for
216 <varname>$XDG_CURRENT_DESKTOP
</varname>, as defined by the
218 url=
"http://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop
219 Entry Specification
</ulink>. (However, note that
220 <varname>$XDG_SESSION_DESKTOP
</varname> only takes a single
221 item, and not a colon-separated list like
222 <varname>$XDG_CURRENT_DESKTOP
</varname>.) See
223 <citerefentry><refentrytitle>sd_session_get_desktop
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
224 for more details.
</para></listitem>
228 <term><varname>$XDG_SEAT
</varname></term>
230 <listitem><para>The seat name the session shall be registered
231 for, if any.
</para></listitem>
235 <term><varname>$XDG_VTNR
</varname></term>
237 <listitem><para>The VT number the session shall be registered
238 for, if any. (Only applies to seats with a VT available, such
239 as
<literal>seat0
</literal>)
</para></listitem>
243 <para>If not set,
<command>pam_systemd
</command> will determine the
244 values for
<varname>$XDG_SEAT
</varname> and
<varname>$XDG_VTNR
</varname>
245 based on the
<varname>$DISPLAY
</varname> variable.
</para>
249 <title>Session limits
</title>
251 <para>PAM modules earlier in the stack, that is those that come before
<command>pam_systemd.so
</command>,
252 can set session scope limits using the PAM context objects. The data for these objects is provided as NUL-terminated C strings
253 and maps directly to the respective unit resource control directives. Note that these limits apply to individual sessions of the user,
254 they do not apply to all user processes as a combined whole. In particular, the per-user
<command>user@.service
</command> unit instance,
255 which runs the
<command>systemd --user
</command> manager process and its children, and is tracked outside of any session, being shared
256 by all the user's sessions, is not covered by these limits.
260 <citerefentry><refentrytitle>systemd.resource-control
</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more information about the resources.
261 Also, see
<citerefentry><refentrytitle>pam_set_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry> for additional information about how to set
267 <term><varname>systemd.memory_max
</varname></term>
269 <listitem><para>Sets unit
<varname>MemoryMax=
</varname>.
</para></listitem>
273 <term><varname>systemd.tasks_max
</varname></term>
275 <listitem><para>Sets unit
<varname>TasksMax=
</varname>.
</para></listitem>
279 <term><varname>systemd.cpu_weight
</varname></term>
281 <listitem><para>Sets unit
<varname>CPUWeight=
</varname>.
</para></listitem>
285 <term><varname>systemd.io_weight
</varname></term>
287 <listitem><para>Sets unit
<varname>IOWeight=
</varname>.
</para></listitem>
291 <para>Example data as can be provided from an another PAM module:
293 pam_set_data(handle,
"systemd.memory_max", (void *)
"200M", cleanup);
294 pam_set_data(handle,
"systemd.tasks_max", (void *)
"50", cleanup);
295 pam_set_data(handle,
"systemd.cpu_weight", (void *)
"100", cleanup);
296 pam_set_data(handle,
"systemd.io_weight", (void *)
"340", cleanup);
303 <title>Example
</title>
305 <programlisting>#%PAM-
1.0
306 auth required pam_unix.so
307 auth required pam_nologin.so
308 account required pam_unix.so
309 password required pam_unix.so
310 session required pam_unix.so
311 session required pam_loginuid.so
312 session required pam_systemd.so
</programlisting>
316 <title>See Also
</title>
318 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
319 <citerefentry><refentrytitle>systemd-logind.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
320 <citerefentry><refentrytitle>logind.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
321 <citerefentry><refentrytitle>loginctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
322 <citerefentry project='man-pages'
><refentrytitle>pam.conf
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
323 <citerefentry project='man-pages'
><refentrytitle>pam.d
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
324 <citerefentry project='man-pages'
><refentrytitle>pam
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
325 <citerefentry project='man-pages'
><refentrytitle>pam_loginuid
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
326 <citerefentry><refentrytitle>systemd.scope
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
327 <citerefentry><refentrytitle>systemd.slice
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
328 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>