KEYCTL_GET_PERSISTENT(2const)
π KEYCTL_GET_PERSISTENT π
okay bestie, welcome to KEYCTL_GET_PERSISTENT(2const) β a lil slice of the Linux man pages, no cap. this one is about snagging a user's persistent keyring and linking it somewhere, and honestly? it's giving β¨immortal key storageβ¨. let's get into it π«Ά
πΈ NAME πΈ
KEYCTL_GET_PERSISTENT β get the persistent keyring for a user
π LIBRARY π
Standard C library (libc, -lc) β the classic, the icon, the one you already have π
β¨ 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_GET_PERSISTENT, uid_t uid,
key_serial_t keyring);
heads up: you're going in raw through syscall(2) here, no glow-up wrapper in sight π (well, mostly β check VERSIONS below, bestie)
π DESCRIPTION π
so what does this thing do? it gets the persistent keyring β that's persistent-keyring(7), the long-lived girlie β for a specified user, and links it to a specified keyring. two things, one syscall, main character energy π
the user ID goes in uid. and here's the cute part: if you pass the value -1, the caller's real user ID is used instead. lazy but valid, we love that for you π
the ID of the destination keyring goes in keyring.
now, permissions check time, because the kernel will vibe check you π. the caller must have the CAP_SETUID capability in its user namespace in order to fetch the persistent keyring for a user ID that does not match either the real or effective user ID of the caller. so likeβ¦ fetching your own? fine. fetching someone else's? you better have the receipts πβ¨
if the call succeeds, a link to the persistent keyring gets added to the keyring whose ID you put in keyring. and β very important β the caller must have write permission on that keyring. no write perm, no link, periodt π
and don't worry about whether the persistent keyring exists yet: the kernel will create it if it doesn't yet exist. she's a self-starter π¦
each time the KEYCTL_GET_PERSISTENT operation is performed, the persistent keyring has its expiration timeout reset to the value in:
/proc/sys/kernel/keys/persistent_keyring_expiry
so every call is basically a lil "hey, still alive? π" text message that refreshes the timer.
β οΈ but if that timeout is reached, the persistent keyring gets removed β and everything it pins can then be garbage collected. bye bestie, it was real πποΈ
also, tiny lore drop: persistent keyrings were added in Linux 3.13.
π«Ά RETURN VALUE π«Ά
- on success β the ID of the persistent keyring. slay π
- on error β
-1is returned, anderrnois set to indicate the error. classic π
π¨ ERRORS π¨
EPERMβuidspecified a UID other than the calling thread's real or effective UID, and the caller did not have theCAP_SETUIDcapability. yeahβ¦ you tried it π
π VERSIONS π
a wrapper is provided in the libkeyutils library: keyctl_get_persistent(3). so if raw syscall(2) isn't your vibe, there's a friendlier door to knock on π
β STANDARDS β
Linux. that's it, that's the tea β (Linux-only, bestie, iykyk)
π°οΈ HISTORY π°οΈ
Linux 3.13.
π SEE ALSO π
and that's the whole page, fr fr π this one came from Linux man-pages 6.20, dated 2026-02-08, filed under KEYCTL_GET_PERSISTENT(2const) β go forth and keyring responsibly, bestie, you got this πΈβ¨π¦
π¦ 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