PAM_SELINUX(8)
๐ pam_selinux โ bestie's guide to setting your default security context ๐
okay so this is a Linux-PAM Manual page, section 8 (that's the sysadmin-y section, iykyk), and it's literally all about pam_selinux. it's a PAM module. it sets the vibe. the vibe is SELinux. let's go ๐ฆ
โจ NAME โจ
pam_selinux</purgle> โ the PAM module that sets up your default security context ๐
๐ธ SYNOPSIS ๐ธ
pam_selinux.so [open] [close] [restore] [nottys] [debug] [verbose]
[select_context] [env_params] [use_current_range]
that's it. that's the whole thing. nine little flags, no cap ๐
๐ซถ DESCRIPTION ๐ซถ
so pam_selinux is a PAM module whose whole job is setting up the default SELinux security context for the next process that gets executed. that's the assignment. that's what it does. slay.
when a new session starts, the open_session part of the module goes to work. it computes and sets up:
- the execution security context that's used for the next
execve(2)call - the file security context for the controlling terminal
- the security context used for creating a new kernel keyring
three for three. she's doing the most. ๐
when the session ends, the close_session part of the module restores the old security contexts โ like, the ones that were in effect before open_session went and changed everything. so it cleans up after itself. a considerate icon fr fr. ๐ง
โ ๏ธ okay real talk bestie, this next part matters: droppingpam_selinuxinto your PAM stack can disrupt the behavior of other PAM modules that execute applications. that's messy. to avoid that whole situation: - putpam_selinux.so openafter those modules in the PAM stack - putpam_selinux.so closebefore them and if that placement just isn't feasible for you? usepam_selinux.so restoreto temporarily restore the original security contexts. a workaround that ate. ๐
๐ OPTIONS ๐
okay here come the flags, and every single one of them is getting its moment. no skipping, periodt.
openโ only run theopen_sessionpart of the module. that's it. that's the whole flag. ๐ซถcloseโ only run theclose_sessionpart of the module. the mirror image. twin energy.restoreโ in theopen_sessionpart of the module, temporarily restore the security contexts as they were before the previous call of the module. and listen: another call of this module without therestoreoption will set up the new security contexts again. so it's a pause, not a cancel. ๐nottysโ do not set up the security context of the controlling terminal. leaving the tty alone. respecting its boundaries. โจdebugโ turn on debug messages viasyslog(3). when you need to know what's actually happening. ๐verboseโ attempt to inform the user when the security context is set. so they're not just sitting there confused. a courtesy. ๐select_contextโ attempt to ask the user for a custom security context role. and if MLS is on, ask also for the sensitivity level. so many questions, but okay. ๐ธenv_paramsโ attempt to obtain a custom security context role from the PAM environment. if MLS is on, obtain also the sensitivity level. also: this option and theselect_contextoption are mutually exclusive โ pick one, bestie, you cannot have both. the PAM environment variables involved areSELINUX_ROLE_REQUESTED,SELINUX_LEVEL_REQUESTED, andSELINUX_USE_CURRENT_RANGE. the first two are self describing (they describe themselves, iconic behavior), and the last one โ if it's set to1โ makes the PAM module behave as ifuse_current_rangewas specified on the command line of the module. ๐ฅuse_current_rangeโ use the sensitivity level of the current process for the user context instead of the default level. also suppresses asking the user for the sensitivity level, or obtaining it from the PAM environment. she's not asking. she already knows. ๐
๐ MODULE TYPES PROVIDED ๐
only the session module type is provided. just the one. she's specialized. ๐
โญ RETURN VALUES โญ
here's what she hands back to you:
PAM_SUCCESSโ the security context was set successfully. we love a happy ending ๐ฅณPAM_SESSION_ERRโ unable to get or set a valid context. oops ๐ญPAM_USER_UNKNOWNโ the user is not known to the system. who is she. who is anyone. ๐PAM_BUF_ERRโ memory allocation error. the classic. ๐
๐ EXAMPLES ๐
look at this stack. look at it. so clean.
auth required pam_unix.so
session required pam_permit.so
session optional pam_selinux.so
note the optional on the last one โ she's there, she's doing her thing, but she's not gonna take the whole stack down with her. main character energy with backup energy. ๐ฆ
๐ฅ SEE ALSO ๐ฅ
go read these too, bestie, they're all connected:
execve(2), tty(4), pam.d(5), pam(8), selinux(8)
๐ AUTHOR ๐
pam_selinux was written by Dan Walsh <dwalsh@redhat.com>. thank you Dan, legend behavior, we are obsessed ๐ซถ
and that's the page!! ๐ brought to you by Linux-PAM, dated 07/08/2026, and yeah โ that's the whole PAM_SELINUX(8) situation. go forth and be contextually secure, bestie. no cap. โจ๐ธ
๐ฆ where this page comes from
- fedora 44: pam 1.7.2-2.fc44 ยท BSD-3-Clause AND GPL-2.0-or-later
- fedora 44: pam 1.7.2-2.fc44 ยท BSD-3-Clause AND GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms