{"id":3240,"date":"2022-12-20T16:43:55","date_gmt":"2022-12-20T19:43:55","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/pam_systemd-man8\/"},"modified":"2022-12-20T16:43:55","modified_gmt":"2022-12-20T19:43:55","slug":"pam_systemd-man8","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/pam_systemd-man8\/","title":{"rendered":"PAM_SYSTEMD (man8)"},"content":{"rendered":"<h1 align=\"center\">PAM_SYSTEMD<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#OPTIONS\">OPTIONS<\/a><br \/> <a href=\"#MODULE TYPES PROVIDED\">MODULE TYPES PROVIDED<\/a><br \/> <a href=\"#ENVIRONMENT\">ENVIRONMENT<\/a><br \/> <a href=\"#SESSION LIMITS\">SESSION LIMITS<\/a><br \/> <a href=\"#EXAMPLE\">EXAMPLE<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">pam_systemd \u2212 Register user sessions in the systemd login manager<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">pam_systemd.so<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>pam_systemd<\/b> registers user sessions with the systemd login manager <b>systemd-logind.service<\/b>(8), and hence the systemd control group hierarchy.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The module also applies various resource management and runtime parameters to the new session, as configured in the <b><font color=\"#0000FF\">JSON User Record<\/font><\/b> <small><font color=\"#000000\">[1]<\/font><\/small> <font color=\"#000000\">of the user, when one is defined.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">On login, this module \u2014 in conjunction with systemd\u2212logind.service \u2014 ensures the following:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">1. If it does not exist yet, the user runtime directory \/run\/user\/$UID is either created or mounted as new &#8220;tmpfs&#8221; file system with quota applied, and its ownership changed to the user that is logging in.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">2. The <i>$XDG_SESSION_ID<\/i> environment variable is initialized. If auditing is available and <b>pam_loginuid.so<\/b> 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.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">3. A new systemd scope unit is created for the session. If this is the first concurrent session of the user, an implicit per\u2212user 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.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">4. The &#8220;$TZ&#8221;, &#8220;$EMAIL&#8221; and &#8220;$LANG&#8221; environment variables are configured for the user, based on the respective data from the user&#8217;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.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">On logout, this module ensures the following:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">1. If enabled in <b>logind.conf<\/b>(5) (<i>KillUserProcesses=<\/i>), all processes of the session are terminated. If the last concurrent session of a user ends, the user&#8217;s systemd instance will be terminated too, and so will the user&#8217;s slice unit.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">2. If the last concurrent session of a user ends, the user runtime directory \/run\/user\/$UID and all its contents are removed, too.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If the system was not booted up with systemd as init system, this module does nothing and immediately returns <b>PAM_SUCCESS<\/b>.<\/font><\/p>\n<h2>OPTIONS <a name=\"OPTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The following options are understood:<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>class=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Takes a string argument which sets the session class. The <i>XDG_SESSION_CLASS<\/i> environment variable (see below) takes precedence. One of &#8220;user&#8221;, &#8220;greeter&#8221;, &#8220;lock\u2212screen&#8221; or &#8220;background&#8221;. See <b>sd_session_get_class<\/b>(3) for details about the session class.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>type=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Takes a string argument which sets the session type. The <i>XDG_SESSION_TYPE<\/i> environment variable (see below) takes precedence. One of &#8220;unspecified&#8221;, &#8220;tty&#8221;, &#8220;x11&#8221;, &#8220;wayland&#8221; or &#8220;mir&#8221;. See <b>sd_session_get_type<\/b>(3) for details about the session type.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>desktop=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Takes a single, short identifier string for the desktop environment. The <i>XDG_SESSION_DESKTOP<\/i> environment variable (see below) takes precedence. This may be used to indicate the session desktop used, where this applies and if this information is available. For example: &#8220;GNOME&#8221;, or &#8220;KDE&#8221;. It is recommended to use the same identifiers and capitalization as for <i>$XDG_CURRENT_DESKTOP<\/i>, as defined by the<\/font> <b><font color=\"#0000FF\">Desktop Entry Specification<\/font><\/b> <small><font color=\"#000000\">[2]<\/font><\/small> <font color=\"#000000\">. (However, note that the option only takes a single item, and not a colon\u2212separated list like <i>$XDG_CURRENT_DESKTOP<\/i>.) See <b>sd_session_get_desktop<\/b>(3) for further details.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>debug<\/i>[=]<\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Takes an optional boolean argument. If yes or without the argument, the module will log debugging information as it operates.<\/font><\/p>\n<h2>MODULE TYPES PROVIDED <a name=\"MODULE TYPES PROVIDED\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Only <b>session<\/b> is provided.<\/font><\/p>\n<h2>ENVIRONMENT <a name=\"ENVIRONMENT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The following environment variables are initialized by the module and available to the processes of the user&#8217;s session:<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$XDG_SESSION_ID<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">A short session identifier, suitable to be used in filenames. The string itself should be considered opaque, although often it is just the audit session ID as reported by \/proc\/self\/sessionid. Each ID will be assigned only once during machine uptime. It may hence be used to uniquely label files or other resources of this session. Combine this ID with the boot identifier, as returned by <b>sd_id128_get_boot<\/b>(3), for a globally unique identifier.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$XDG_RUNTIME_DIR<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Path to a user\u2212private user\u2212writable directory that is bound to the user login time on the machine. It is automatically created the first time a user logs in and removed on the user&#8217;s final logout. If a user logs in twice at the same time, both sessions will see the same <i>$XDG_RUNTIME_DIR<\/i> and the same contents. If a user logs in once, then 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\u2212private data in this directory, the user should include the value of <i>$XDG_SESSION_ID<\/i> in the filename. This directory shall be used for runtime file system objects such as <b>AF_UNIX<\/b> sockets, FIFOs, PID files and similar. It is guaranteed that this directory is local and offers the greatest possible file system feature set the operating system provides. For further details, see the<\/font> <b><font color=\"#0000FF\">XDG Base Directory Specification<\/font><\/b> <small><font color=\"#000000\">[3]<\/font><\/small> <font color=\"#000000\">. <i>$XDG_RUNTIME_DIR<\/i> is not set if the current user is not the original user of the session.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$TZ<\/i>, <i>$EMAIL<\/i>, <i>$LANG<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">If a JSON user record is known for the user logging in these variables are initialized from the respective data in the record.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The following environment variables are read by the module and may be used by the PAM service to pass metadata to the module. If these variables are not set when the PAM module is invoked but can be determined otherwise they are set by the module, so that these variables are initialized for the session and applications if known at all.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$XDG_SESSION_TYPE<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">The session type. This may be used instead of <i>type=<\/i> on the module parameter line, and is usually preferred.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$XDG_SESSION_CLASS<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">The session class. This may be used instead of <i>class=<\/i> on the module parameter line, and is usually preferred.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$XDG_SESSION_DESKTOP<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">The desktop identifier. This may be used instead of <i>desktop=<\/i> on the module parameter line, and is usually preferred.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$XDG_SEAT<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">The seat name the session shall be registered for, if any.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>$XDG_VTNR<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">The VT number the session shall be registered for, if any. (Only applies to seats with a VT available, such as &#8220;seat0&#8221;)<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If not set, <b>pam_systemd<\/b> will initialize <i>$XDG_SEAT<\/i> and <i>$XDG_VTNR<\/i> based on the <i>$DISPLAY<\/i> variable (if the latter is set).<\/font><\/p>\n<h2>SESSION LIMITS <a name=\"SESSION LIMITS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">PAM modules earlier in the stack, that is those that come before <b>pam_systemd.so<\/b>, can set session scope limits using the PAM context objects. The data for these objects is provided as NUL\u2212terminated C strings and maps directly to the respective unit resource control directives. Note that these limits apply to individual sessions of the user, they do not apply to all user processes as a combined whole. In particular, the per\u2212user <b>user@.service<\/b> unit instance, which runs the <b>systemd \u2212\u2212user<\/b> manager process and its children, and is tracked outside of any session, being shared by all the user&#8217;s sessions, is not covered by these limits.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">See <b>systemd.resource-control<\/b>(5) for more information about the resources. Also, see <b>pam_set_data<\/b>(3) for additional information about how to set the context objects.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>systemd.memory_max=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Sets unit <i>MemoryMax=<\/i>.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>systemd.tasks_max=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Sets unit <i>TasksMax=<\/i>.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>systemd.cpu_weight=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Sets unit <i>CPUWeight=<\/i>.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>systemd.io_weight=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Sets unit <i>IOWeight=<\/i>.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><i>systemd.runtime_max_sec=<\/i><\/font><\/p>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">Sets unit <i>RuntimeMaxSec=<\/i>.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Example data as can be provided from an another PAM module:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">pam_set_data(handle, &#8220;systemd.memory_max&#8221;, (void *)&#8221;200M&#8221;, cleanup); <br \/> pam_set_data(handle, &#8220;systemd.tasks_max&#8221;, (void *)&#8221;50&#8243;, cleanup); <br \/> pam_set_data(handle, &#8220;systemd.cpu_weight&#8221;, (void *)&#8221;100&#8243;, cleanup); <br \/> pam_set_data(handle, &#8220;systemd.io_weight&#8221;, (void *)&#8221;340&#8243;, cleanup); <br \/> pam_set_data(handle, &#8220;systemd.runtime_max_sec&#8221;, (void *)&#8221;3600&#8243;, cleanup);<\/font><\/p>\n<h2>EXAMPLE <a name=\"EXAMPLE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Here&#8217;s an example PAM configuration fragment that allows users sessions to be managed by systemd\u2212logind.service:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#%PAM\u22121.0 <br \/> auth sufficient pam_unix.so <br \/> \u2212auth sufficient pam_systemd_home.so <br \/> auth required pam_deny.so<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">account required pam_nologin.so <br \/> \u2212account sufficient pam_systemd_home.so <br \/> account sufficient pam_unix.so <br \/> account required pam_permit.so<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2212password sufficient pam_systemd_home.so <br \/> password sufficient pam_unix.so sha512 shadow try_first_pass use_authtok<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">password required pam_deny.so<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2212session optional pam_keyinit.so revoke <br \/> \u2212session optional pam_loginuid.so <br \/> \u2212session optional pam_systemd_home.so <b><br \/> \u2212session optional pam_systemd.so<\/b> <br \/> session required pam_unix.so<\/font><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><b>systemd<\/b>(1), <b>systemd-logind.service<\/b>(8), <b>logind.conf<\/b>(5), <b>loginctl<\/b>(1), <b>pam_systemd_home<\/b>(8), <b>pam.conf<\/b>(5), <b>pam.d<\/b>(5), <b>pam<\/b>(8), <b>pam_loginuid<\/b>(8), <b>systemd.scope<\/b>(5), <b>systemd.slice<\/b>(5), <b>systemd.service<\/b>(5)<\/font><\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">1.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"25%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">JSON User Record<\/font><\/p>\n<\/td>\n<td width=\"58%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">https:\/\/systemd.io\/USER_RECORD<\/font><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">2.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"41%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">Desktop Entry Specification<\/font><\/p>\n<\/td>\n<td width=\"42%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">http:\/\/standards.freedesktop.org\/desktop-entry-spec\/latest\/<\/font><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">3.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"49%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">XDG Base Directory Specification<\/font><\/p>\n<\/td>\n<td width=\"34%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">http:\/\/standards.freedesktop.org\/basedir-spec\/basedir-spec-latest.html<\/font><\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  pam_systemd \u2212 Register user sessions in the systemd login manager <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,52,4,377],"class_list":["post-3240","post","type-post","status-publish","format-standard","hentry","category-8-administracion-del-sistema","tag-5","tag-administracion","tag-man8","tag-pam_systemd"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=3240"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3240\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=3240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=3240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=3240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}