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
descisNULL, 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,
descis 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,
-1is returned, anderrnois 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
- Copyright 2016, Michael Kerrisk <mtk.manpages@gmail.com>
- Copyright 2016, Eugene Syromyatnikov <evgsyr@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms