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 β€” -1 is returned, and errno is set to indicate the error. classic πŸ˜”

🚨 ERRORS 🚨

  • EPERM β€” uid specified a UID other than the calling thread's real or effective UID, and the caller did not have the CAP_SETUID capability. 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms