KEYCTL_GET_PERSISTENT(3)
π KEYCTL_GET_PERSISTENT π
okay bestie, gather round, because we're diving into keyctl_get_persistent β a page straight out of the Linux Key Management Calls manual (section 3, library functions, iykyk). it's giving "the keyring that refuses to leave the group chat" energy and honestly? iconic. π
β¨ NAME β¨
keyctl_get_persistent β grab the persistent keyring for a user, no cap π
β¨ SYNOPSIS β¨
#include <keyutils.h>
long keyctl_get_persistent(uid_t uid, key_serial_t keyring);
like, that's it. two args. she's low maintenance, she's efficient, she's main character energy π
β¨ DESCRIPTION β¨
so keyctl_get_persistent() gets the persistent keyring for the user ID you point at. and here's the tea β β unlike the session and user keyrings, this one persists once every single login session has been deleted. meaning she sticks around. meaning you can use her to carry authentication tokens for processes that run with zero user interaction, like stuff started by cron. yes, cron. the little background gremlin that never asks for your password π
the kernel will create the persistent keyring for you if it doesn't exist yet β no need to manifest it yourself, she just shows up π¦
and every single time this function gets called, the persistent keyring's expiration timeout gets reset to whatever value lives in:
/proc/sys/kernel/keys/persistent_keyring_expiry
which, btw, defaults to three days β³
and if that timeout ever actually gets reached? the persistent keyring gets removed, and everything it was pinning can then be garbage collected. rip to her fr fr π
now, the uid rules, listen closely:
- if
uidis-1, then the calling process's real user ID gets used. easy, no thoughts, just vibes. - if
uidis not-1, then errorEPERMwill be given if the user ID you requested doesn't match either the caller's real or effective user IDs, or if the calling process doesn't have SetUid capability. so like, know your limits bestie π«Ά
and if it all goes well? a link to the persistent keyring gets added into keyring. slay. β¨
β¨ RETURN VALUE β¨
on success, keyctl_get_persistent() returns the serial number of the persistent keyring. a whole number, a whole identity, a whole queen π
on error, the value -1 gets returned and errno will have been set to an appropriate error. classic. π
β¨ ERRORS β¨
here's the mood board of ways this can go wrong, and every single one matters:
EPERMβ not permitted to access the persistent keyring for the requesteduid. the bouncer said no πENOMEMβ insufficient memory to create the persistent keyring or to extendkeyring. she's out of RAM and out of patience.ENOKEYβkeyringdoes not exist. never was. never will be. ghosted πEKEYEXPIREDβkeyringhas expired. the timer ran out, bestie.EKEYREVOKEDβkeyringhas been revoked. cancelled, actually.EDQUOTβ the user does not have sufficient quota to extendkeyring. quota said no more, you're maxed out πEACCESβkeyringexists, but does not grant write permission to the calling process. she's there, she's just not letting you in π
β¨ LINKING β¨
this is a library function, and you'll find her hanging out in libkeyutils. so when you're linking, you gotta pass -lkeyutils to the linker. don't forget it, or the linker will simply not know her and that would be embarrassing π
β¨ SEE ALSO β¨
the whole friend group, go say hi:
keyctl(1)add_key(2)keyctl(2)request_key(2)keyctl(3)keyrings(7)keyutils(7)persistent-keyring(7)
and that's the whole page, bestie!! β¨ no thoughts, just keyrings that outlive your login sessions π this page came to you from the Linux manual, dated 20 Feb 2014, and it's a total banger. go forth and persist. periodt. π
π¦ where this page comes from
- alpine 3.22: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.23: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.24: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- arch rolling: keyutils 1.6.3-4 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 10: keyutils-libs-devel 1.6.3-5.el10 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- debian bookworm: libkeyutils-dev 1.6.3-2 Β· GPL-2.0-or-later
- debian trixie: libkeyutils-dev 1.6.3-6 Β· GPL-2.0-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- nixpkgs unstable: keyutils 1.6.3
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- ubuntu jammy: libkeyutils-dev 1.6.1-2ubuntu3 Β· GPL-2.0-or-later
- ubuntu noble: libkeyutils-dev 1.6.3-3build1 Β· GPL-2.0-or-later
- ubuntu questing: libkeyutils-dev 1.6.3-6ubuntu2
- ubuntu resolute: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- ubuntu stonking: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- Copyright (C) 2013 Red Hat, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms