USER-SESSION-KEYRING(7)

๐Ÿ’– USER-SESSION-KEYRING ๐Ÿ’–

okay bestie so the manual name is user-session-keyring(7) and it lives in the Miscellaneous Information Manual, and no cap, it is genuinely one of the most "wait what is my kernel even doing" pages out there. sit down, get cozy ๐Ÿซถ


โœจ NAME โœจ

user-session-keyring โ€” the per-user default session keyring ๐Ÿ‘‘


๐ŸŒธ DESCRIPTION ๐ŸŒธ

so. the user session keyring is a keyring, and its whole job is anchoring keys on behalf of a user. like it's the little home base for your keys, bestie. ๐Ÿ 

every single UID the kernel deals with gets its own user session keyring, and โ€” this is the important part โ€” it's shared by all processes with that UID. not per-process, not per-thread. one UID, one vibe. ๐Ÿ’…

it has a name (description, same thing) that looks like this:

_uid_ses.<UID>

where <UID> is literally just the user ID of the corresponding user. so if you're UID 1000, your keyring is _uid_ses.1000. iconic. ๐ŸŽ€

the user session keyring is associated with the record that the kernel maintains for the UID. and the way it comes into existence? not at boot, not on login โ€” it shows up upon the first attempt to access any of:

(three doors, same room. iykyk ๐ŸŒˆ)

and then it stays pinned in existence for as long as there are either (a) processes running with that real UID, or (b) files opened by those processes that remain open. also, side note: it can be pinned indefinitely if you link it into another keyring. so it can outlive basically everything if you want it to. main character energy fr fr. ๐Ÿ‘‘

the creation story goes like this: it's created on demand when a thread requests it, OR when a thread asks for its session-keyring(7) and that session keyring doesn't exist. in that second case, a user session keyring gets created, and here's the spicy bit โ€” if the session keyring wasn't to be created, then the user session keyring gets set as the process's actual session keyring. sneaky little substitution, love that for it. ๐Ÿฆ‹

who talks to it? request_key(2) searches it, but ONLY if the actual session keyring does not exist. if the actual session keyring does exist, then request_key(2) ignores the user session keyring entirely. read that again, it matters. ๐Ÿ™ˆ

there's also a special serial number value for when you don't have the real serial number handy:

KEY_SPEC_USER_SESSION_KEYRING

throw that in in lieu of the actual serial number of the calling process's user session keyring. and if you're in the keyctl(1) utility, you can just use @us instead of a numeric key ID โ€” same idea, way less typing, so slay. โœจ

now, the independence era: user session keyrings are independent of clone(2), fork(2), vfork(2), execve(2), and _exit(3) โ€” with the one exception that the keyring gets destroyed when the UID record is destroyed, which happens when the last process pinning it exits. that's the whole exception. everything else just doesn't touch it. periodt. ๐Ÿ’œ

oh and also, if a user session keyring does not exist when it is accessed? it will be created. yes, again. it's very "if you build it they will come" but in reverse, it builds itself the second you look at it ๐Ÿ‘€

โš ๏ธ real talk bestie, please read this one: rather than relying on the user session keyring, it is strongly recommended โ€” especially if the process is running as root โ€” that a session-keyring(7) be set explicitly, for example by pam_keyinit(8). this is not a suggestion, this is the "please do not ship root with vibes only" warning. ๐Ÿ™

๐Ÿ“ NOTES ๐Ÿ“

why does this thing even exist, you ask? great question, bestie.

the user session keyring was added to support situations where a process doesn't have a session keyring โ€” perhaaaps because it was created via a pathway that didn't involve PAM (for example, maybe it was a daemon started by inetd(8)). yeah. that kind of process. no PAM, no session keyring, just existential dread and sockets. ๐Ÿ’€

in such a scenario, the user session keyring acts as a substitute for the session-keyring(7). it's the understudy who goes on every single night. it's holding it down. ๐ŸŽญ


๐Ÿ”— SEE ALSO ๐Ÿ”—

the whole keyring cinematic universe, honestly. go read all of them. ๐ŸŒˆโญ


and that's the page!! ๐Ÿ’– thanks for coming to my ted talk, this one shipped as part of Linux man-pages 6.20, dated 2026-06-05 โ€” go forth and keyctl responsibly, bestie ๐ŸŽ€โœจ๐Ÿซถ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: 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