KEYCTL_JOIN_SESSION_KEYRING(2const)

πŸ’– KEYCTL_JOIN_SESSION_KEYRING πŸ’–

okay bestie, so you know how a process has a session keyring it's subscribed to? This is the keyctl(2) operation that swaps it out for a whole new one. Glow-up time for your keyring. πŸ‘‘

It's a KEYCTL_* constant from the Linux kernel's key management syscall family β€” the page lives in section 2const, so if you were looking for the manual name, it's keyctl_join_session_keyring(2const). ✨


πŸ“š LIBRARY

Standard C library (libc, -lc). Yep, the basic one, no extras needed. πŸ’…


✨ SYNOPSIS ✨

#include <linux/keyctl.h>  /* Definition of KEY* constants */
#include <sys/syscall.h>   /* Definition of SYS_* constants */
#include <unistd.h>

long syscall(SYS_keyctl, KEYCTL_JOIN_SESSION_KEYRING,
             char *_Nullable desc);

note that desc is _Nullable, so handing over a NULL is a whole valid vibe here, not a mistake. 🫢


🌸 DESCRIPTION 🌸

So the whole point: replace the session keyring this process subscribes to with a new session keyring. That's it. That's the gig. New keyring, who dis. πŸ’–

Now here's where it branches, and this part is important, so pay attention bestie:

  • If desc is NULL, an anonymous keyring with the description "_ses" gets created, and the process is subscribed to that keyring as its session keyring, displacing whatever session keyring it had before. Say bye to the old one. πŸ‘‹
  • Otherwise, desc is treated as the description (aka the name) of a keyring, and then the behavior goes like this:
    • If a keyring with a matching description exists, the process will attempt to subscribe to that keyring as its session keyring if possible; if that is not possible, an error is returned. And heads up β€” in order to subscribe to that keyring, the caller must have search permission on the keyring. No permission, no entry, periodt. πŸ”’
    • If a keyring with a matching description does not exist, then a brand new keyring with the specified description is created, and the process is subscribed to that keyring as its session keyring. Manifesting a keyring into existence, iconic behavior honestly. 🌈

πŸŽ€ RETURN VALUE πŸŽ€

  • On success, you get the ID of the joined session keyring. Treasure it. πŸ‘‘
  • On error, -1 is returned, and errno is set to indicate the error. Classic. πŸ’€

πŸ¦‹ VERSIONS πŸ¦‹

There's a cute lil wrapper for this over in the libkeyutils library: keyctl_join_session_keyring(3). Use it if you don't wanna rawdog the syscall. πŸ™ˆ


⭐ STANDARDS ⭐

Linux. Just Linux. That's the whole standard. πŸ’œ


🌸 HISTORY 🌸

Linux 2.6.10 β€” this has been around since way back, it's a certified elder. πŸ‘‘


πŸ’… SEE ALSO πŸ’…


okay that's the whole thing, you're so welcome, go forth and subscribe to keyrings responsibly 🫢

this was brought to you by Linux man-pages 6.20, dated 2026-02-0, mwah πŸ’‹

πŸ“¦ 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: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms