PAM_SYSTEMD(8)

๐Ÿ’– pam_systemd ๐Ÿ’–

section 8, bestie โ€” like, the manual page for pam_systemd, no cap โœจ


๐ŸŽ€ NAME ๐ŸŽ€

pam_systemd โ€” registers user sessions in the systemd login manager ๐Ÿซถ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

pam_systemd.so

๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so. pam_systemd registers user sessions with the systemd login manager systemd-logind.service(8), and hence the systemd control group hierarchy. that's the whole vibe ๐Ÿ’…

the module also applies various resource management and runtime parameters to the new session, as configured in the JSON User Records[1] of the user, when one is defined. โœจ

On login, this module โ€” in conjunction with systemd-logind.service โ€” ensures the following, bestie:

  1. If it does not exist yet, the user runtime directory /run/user/$UID is either created or mounted as new "tmpfs" file system with quota applied, and its ownership changed to the user that is logging in. ๐Ÿ—‚๏ธ
  2. The $XDG_SESSION_ID environment variable is initialized. If auditing is available and pam_loginuid.so was run before this module (which is highly recommended), the variable is initialized from the auditing session id (/proc/self/sessionid). Otherwise, an independent session counter is used. ๐Ÿ”
  3. A new systemd scope unit is created for the session. If this is the first concurrent session of the user, an implicit per-user slice unit below user.slice is automatically created and the scope placed into it. An instance of the system service user@.service, which runs the systemd user manager instance, is started. ๐Ÿ‘‘
  4. The "$TZ", "$EMAIL" and "$LANG" environment variables are configured for the user, based on the respective data from the user's JSON record (if it is defined). Moreover, any environment variables explicitly configured in the user record are imported, and the umask, nice level, and resource limits initialized. ๐ŸŒˆ

On logout, this module ensures the following:

  1. If enabled in logind.conf(5) (KillUserProcesses=), all processes of the session are terminated. If the last concurrent session of a user ends, the user's systemd instance will be terminated too, and so will the user's slice unit. ๐Ÿ’€
  2. If the last concurrent session of a user ends, the user runtime directory /run/user/$UID and all its contents are removed, too. ๐Ÿงน
heads up: if the system was not booted up with systemd as init system, this module does nothing and immediately returns PAM_SUCCESS. literally just vibes and no action ๐Ÿ™ˆ

โœจ OPTIONS โœจ

the following options are understood, bestie, write these down:

  • class= โ€” takes a string argument which sets the session class. The XDG_SESSION_CLASS environment variable (see below) takes precedence. See sd_session_get_class(3) for a way to query the class of a session. The following session classes are defined:

๐Ÿ“‹ Table 1. Session Classes ๐Ÿ“‹

  • user โ€” 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. ๐Ÿ‘‘
  • user-early โ€” similar to user but sessions of this class are not ordered after systemd-user-sessions.service(8), 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 user class, see above. (Added in v256.) ๐ŸŒ…
  • user-light โ€” similar to user, but sessions of this class will not pull in the user@.service(5) of the user, and thus possibly have no service manager of the user running. (Added in v258.) ๐Ÿชถ
  • user-early-light โ€” similar to user-early, but sessions of this class will not pull in the user@.service(5) of the user, and thus possibly have no service manager of the user running. (Added in v258.) ๐Ÿ“
  • user-incomplete โ€” similar to user but for sessions which are not fully set up yet, i.e. have no home directory mounted or similar. This is used by systemd-homed.service(8) to allow users to log in via ssh(1) before their home directory is mounted, delaying the mount until the user provided the unlock password. Sessions of this class are upgraded to the regular user class once the home directory is activated. ๐Ÿ”
  • greeter โ€” similar to user but for sessions that are spawned by a display manager ephemerally and which prompt the user for login credentials. ๐ŸŽ€
  • lock-screen โ€” similar to user 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. ๐Ÿ”’
  • background โ€” used for background sessions, such as those invoked by cron(8) and similar tools. This is the default class for sessions for which no TTY or X display is known at session registration time. ๐ŸŒ™
  • background-light โ€” similar to background, but sessions of this class will not pull in the user@.service(5) of the user, and thus possibly have no service manager of the user running. (Added in v256.) ๐ŸŒซ๏ธ
  • manager โ€” the user@.service(5) service of the user is registered under this session class. (Added in v256.) ๐Ÿ’ผ
  • manager-early โ€” similar to manager, but for the root user. Compare with the user vs. user-early situation. (Added in v256.) ๐ŸŒ„
  • none โ€” skips registering this session with logind. No session scope will be created, and the user service manager will not be started. (Added in v258.) ๐Ÿšซ

So if you didn't hand over a session class via the PAM module option or via $XDG_SESSION_CLASS, bestie, the module justโ€ฆ picks one for you. It looks at all the session tea: the session type (if it even knows it), whether the session has a TTY or an X11 display, and the user disposition. And here's the fun part โ€” lots of tools let you set the session class for freshly allocated PAM sessions explicitly through $XDG_SESSION_CLASS. For example, classic UNIX cronjobs support environment variable assignments (peep crontab(5)), so you can choose between the background and background-light session class individually per cronjob, or run0 --setenv=XDG_SESSION_CLASS=user-light to choose between user and user-light for invoked privileged sessions. ๐Ÿ’…

Added in version 197.

  • type= โ€” takes a string argument that sets the session type. The $XDG_SESSION_TYPE environment variable (more on that below) wins if it's set. Pick one of unspecified, tty, x11, wayland, mir, or web. Wanna know the lore on session types? That's sd_session_get_type(3). โœจ

Added in version 209.

  • desktop= โ€” takes a single, short identifier string for the desktop environment. The $XDG_SESSION_DESKTOP environment variable (see below) takes precedence. Use this to indicate the session desktop, where it applies and if you actually have that info. Like: GNOME, or KDE. Highly recommend using the same identifiers and capitalization as for $XDG_CURRENT_DESKTOP, as defined by the Desktop Entry Specification[2]. (But heads up โ€” this option only takes a single item, not a colon-separated list like $XDG_CURRENT_DESKTOP does. ๐Ÿ™ˆ) See sd_session_get_desktop(3) for further details.

Added in version 240.

  • area= โ€” takes a filename as parameter. If you set it and the user logs into their account, $HOME gets set to ~/Areas/ suffixed by the specified string โ€” but only if that directory exists. Also, $XDG_AREA gets set to the (unprefixed) parameter.

This is the move for maintaining multiple separate secondary home directories inside the user's primary home directory. Usually the area you log into gets specified while logging in, if the account allows it (accounts from pam_systemd_home(8) do!), but this parameter can define a default for when that's not provided. ๐Ÿ 

Real talk though: this only adjusts $HOME during login. It does not touch the otherwise reported home directory of the user. Which means sshd(8) will keep looking for the user's SSH keys only in their primary home directory, never in any of their areas. ๐Ÿ”‘

Also note that the default area to log into can be configured as part of the user account too. The area you specify via area= overrides the default area configured there. And if the user specifies the area explicitly at login time, that overrides both. And setting this parameter to an empty string undoes the effect of any default area configured as part of the user record โ€” i.e. it ensures the user logs into the primary home directory of their account. ๐Ÿ’ซ

For all the deets on the area concept, see pam_systemd_home(8).

Added in version 258.

  • inhibit= โ€” takes a colon-separated list of inhibitor lock types to acquire for the duration of the session. The $XDG_SESSION_INHIBIT environment variable (see below) takes precedence. Inhibitor locks stop the system from doing certain things โ€” like sleeping. The supported lock types are the exact same as for the systemd-inhibit(1) command, e.g. shutdown, sleep, idle. If you don't set it, no inhibitor lock is acquired. The lock is taken in block mode, so the requested actions are fully inhibited for as long as the session is active. ๐Ÿ˜ด๐Ÿšซ

Added in version 262.

  • inhibit-why= โ€” takes a short human-readable string describing why you grabbed the inhibitor lock from inhibit=. The $XDG_SESSION_INHIBIT_WHY environment variable (see below) takes precedence. Defaults to "Active PAM session" if not set. Only does anything if inhibit= or XDG_SESSION_INHIBIT is set. ๐Ÿ’ฌ

Added in version 262.

  • default-capability-bounding-set=, default-capability-ambient-set= โ€” takes a comma-separated list of process capabilities (e.g. CAP_WAKE_ALARM, CAP_BLOCK_SUSPEND, ...) to set for the invoked session's processes, if the user record doesn't already encode appropriate sets of capabilities directly. See capabilities(7) for the whole capabilities concept. If not specified, the default bounding set is left as is (i.e. usually contains the full set of capabilities). The default ambient set is set to CAP_WAKE_ALARM for regular users if the PAM session is associated with a local seat, or if it's invoked for the systemd user service user@.service. Otherwise, it defaults to the empty set. ๐Ÿ‘‘

Added in version 254.

  • debug[=] โ€” takes an optional boolean argument. If yes, or if you give it no argument at all, the module logs debugging info as it operates. ๐Ÿ›

๐ŸŽ€ MODULE TYPES PROVIDED ๐ŸŽ€

Only session is provided. That's it. That's the whole list. Iconic behaviour, honestly. ๐Ÿ’…


๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

These environment variables get initialized by the module and are available to the processes of the user's session, bestie:

  • $XDG_SESSION_ID โ€” a short session identifier, perfect for filenames. The string itself should be considered opaque, even though it's often just the audit session ID as reported by /proc/self/sessionid. Each ID gets assigned only once during machine uptime, so you can use it to uniquely label files or other resources of this session. Combine this ID with the boot identifier, as returned by sd_id128_get_boot(3), for a globally unique identifier. ๐Ÿ†”
  • $XDG_RUNTIME_DIR โ€” path to a user-private, user-writable directory that's bound to the user's login time on the machine. It's automatically created the first time a user logs in and removed on the user's final logout. If a user logs in twice at the same time, both sessions see the same $XDG_RUNTIME_DIR and the same contents. If a user logs in once, logs out again, and logs in again, the directory contents will have been lost in between โ€” but applications should not rely on this behavior and must be able to deal with stale files. To store session-private data in this directory, the user should include the value of $XDG_SESSION_ID in the filename. This directory shall be used for runtime file system objects such as AF_UNIX sockets, FIFOs, PID files and similar. It's guaranteed that this directory is local and offers the greatest possible file system feature set the operating system provides. For further details, see the XDG Base Directory Specification[3]. And lowkey important: $XDG_RUNTIME_DIR is not set if the current user is not the original user of the session. ๐Ÿ“
  • $TZ, $EMAIL, $LANG โ€” if a JSON user record is known for the user logging in, these variables get initialized from the respective data in that record. โœจ

Added in version 245.

  • $SHELL_PROMPT_PREFIX, $SHELL_PROMPT_SUFFIX, $SHELL_WELCOME โ€” these get initialized from the service credentials "shell.prompt.prefix", "shell.prompt.suffix" and "shell.welcome" if they're set. They're passed to the invoked session processes, where they get imported into any shell prompt (specifically, $SHELL_PROMPT_PREFIX is added as prefix to $PS1, and $SHELL_PROMPT_SUFFIX as suffix) or printed on screen when a shell first initializes. ๐Ÿš๐Ÿ’–

Added in version 257.

Now for the ones the module reads. These can be used by the PAM service to pass metadata to the module. And plot twist โ€” if these variables aren't set when the PAM module is invoked but can be determined otherwise, the module sets them itself, so they end up initialized for the session and applications if known at all:

  • $XDG_SESSION_TYPE โ€” the session type. Use this instead of type= on the module parameter line โ€” it's usually preferred. โœจ

Added in version 209.

  • $XDG_SESSION_CLASS โ€” the session class. Use this instead of class= on the module parameter line, and yeah, it's usually preferred. ๐ŸŽ€

Added in version 209.

  • $XDG_SESSION_DESKTOP โ€” the desktop identifier. Use this instead of desktop= on the module parameter line, and again, usually preferred. ๐Ÿ–ฅ๏ธ

Added in version 209.

  • $XDG_SEAT โ€” the seat name the session shall be registered for, if any. ๐Ÿ’บ

Added in version 209.

  • $XDG_VTNR โ€” the VT number the session shall be registered for, if any. (Only applies to seats with a VT available, such as "seat0".) ๐Ÿ”ข

Added in version 209.

  • $XDG_AREA โ€” if an area (secondary home directories of the user, within the primary home directory) to log into has been selected, this variable gets set to the area name (without any path prefix). Otherwise it's unset. For all the area details, see above. ๐Ÿ 

Added in version 258.

  • $XDG_SESSION_EXTRA_DEVICE_ACCESS โ€” the set of additional hardware devices the session shall be granted access to. For every "ID" in the list, the session is granted access to all devices tagged with "xaccess-ID" in udev. ๐Ÿ”Œ

Added in version 260.

  • $XDG_SESSION_INHIBIT โ€” the inhibitor lock types to acquire for the duration of the session, as a colon-separated list. Use this instead of inhibit= on the module parameter line. ๐Ÿ˜ด

Added in version 262.

  • $XDG_SESSION_INHIBIT_WHY โ€” the reason string for the inhibitor lock. Use this instead of inhibit-why= on the module parameter line. ๐Ÿ’ฌ

Added in version 262.

And if they're not set, pam_systemd will initialize $XDG_SEAT and $XDG_VTNR based on the $DISPLAY variable (if the latter is set). No cap. ๐Ÿฆ‹

๐ŸŒธ SESSION LIMITS ๐ŸŒธ

Okay bestie, this part is lowkey the most powerful one, so pay attention. PAM modules that come earlier in the stack โ€” meaning the ones that come before pam_systemd.so โ€” can set session scope limits using the PAM context objects. ๐Ÿ’…

The data for these objects gets handed over as NUL-terminated C strings</>, and it maps directly</> onto the respective unit resource control directives. So like, no middleman, no vibes-based translation. โœจ

โš ๏ธ Real talk though: these limits apply to individual sessions of the user. They do not apply to all user processes as one big combined whole. Specifically, the per-user user@.service unit instance โ€” the one that runs the systemd --user manager process and its children โ€” is tracked outside of any session, gets shared by all the user's sessions, and is not covered by these limits. So don't come for it. ๐Ÿ’€

Want the full lore on what these resources even are? Go read systemd.resource-control(5). And for how to actually set the context objects, check pam_set_data(3). ๐Ÿซถ


  • systemd.memory_max= โ€” sets unit MemoryMax=. (added in version 239) โœจ
  • systemd.tasks_max= โ€” sets unit TasksMax=. (added in version 239) โœจ
  • systemd.cpu_weight= โ€” sets unit CPUWeight=. (added in version 239) โœจ
  • systemd.io_weight= โ€” sets unit IOWeight=. (added in version 239) โœจ
  • systemd.runtime_max_sec= โ€” sets unit RuntimeMaxSec=. (added in version 244) โœจ

Example data as can be provided from an another PAM module, and yes this is verbatim so type it exactly bestie:

pam_set_data(handle, "systemd.memory_max", (void *)"200M", cleanup);
pam_set_data(handle, "systemd.tasks_max",  (void *)"50",   cleanup);
pam_set_data(handle, "systemd.cpu_weight", (void *)"100",  cleanup);
pam_set_data(handle, "systemd.io_weight",  (void *)"340",  cleanup);
pam_set_data(handle, "systemd.runtime_max_sec", (void *)"3600", cleanup);

๐ŸŒˆ EXAMPLE ๐ŸŒˆ

Here's an example PAM configuration fragment that lets users' sessions be managed by systemd-logind.service. It's giving main character config file. Copy it exactly, no edits, no notes:

#%PAM-1.0
-auth     [success=done authtok_err=bad perm_denied=bad maxtries=bad default=ignore] pam_systemd_home.so
auth      sufficient pam_unix.so
auth      required   pam_deny.so

account   required   pam_nologin.so
-account  [success=done authtok_expired=bad new_authtok_reqd=bad maxtries=bad acct_expired=bad default=ignore] pam_systemd_home.so
account   required   pam_unix.so

-password sufficient pam_systemd_home.so
password  sufficient pam_unix.so sha512 shadow try_first_pass
password  required   pam_deny.so

-session  optional   pam_keyinit.so revoke
-session  optional   pam_loginuid.so
-session  optional   pam_systemd_home.so
-session  optional   pam_systemd.so
session   required   pam_unix.so

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

Go read these when you're done here, they're all iconic in their own way:


๐Ÿ“Ž NOTES ๐Ÿ“Ž

  1. JSON User Records โ€” https://systemd.io/USER_RECORD
  2. Desktop Entry Specification โ€” https://standards.freedesktop.org/desktop-entry-spec/latest/
  3. XDG Base Directory Specification โ€” https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

And that's the whole page, bestie!! ๐ŸŽ€ This one is from systemd 262.1, and yeah, it's PAM_SYSTEMD(8) โ€” go forth and manage those sessions, you absolute icon. ๐Ÿ’–โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from
  • arch rolling: systemd 262.1-1 ยท LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later AND MIT-0
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms