KEYCTL_SEARCH(2const)
π KEYCTL_SEARCH β bestie, let's go find ur key πβ¨
okay so this is a page from the KEYCTL_SEARCH(2const) manual, and honestly? it's giving treasure hunt. we're searching a keyring tree for a key and getting its ID back. no cap. π
π LIBRARY
Standard C library (libc, -lc). the classic. π
β¨ 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_SEARCH, key_serial_t src,
char *type, char *desc,
unsigned long dst);
πΈ DESCRIPTION
So basically: we're searching for a key inside a keyring tree, and when we find it we get its ID back β and optionally we can link it into a keyring we pick. iconic behavior honestly. π
The tree we're searching is picked by passing the ID of the head keyring in src. The search goes down breadth-first and recursively. (yes bestie, it's methodical. it does not skip steps. main character energy. π)
The type and desc arguments say which key we're looking for:
typeholds the key type β a null-terminated character string up to 32 bytes in size, and that size includes the terminating null byte.descholds the key's description β a null-terminated character string up to 4096 bytes in size, also including the terminating null byte. 4096!! big mood.
The source keyring has to grant search permission to the caller. And when it's doing the recursive search, only the keyrings that grant the caller search permission get searched at all. Same energy for the find itself: only keys that the caller has search permission for can actually be found. πͺβ¨ (no permission, no entry, periodt.)
If the key is found, its ID is returned as the function result. slay. π
If the key is found and dst is nonzero, then β subject to the exact same constraints and rules as KEYCTL_LINK(2const) β the key gets linked into the keyring whose ID is in dst. And heads up: if the destination keyring in dst already has a link to a key with the same type and description, then that link gets displaced by a link to the key this operation found. it's giving "move over, i'm the link now". π
Also, instead of valid existing keyring IDs, the source (src) and destination (dst) keyrings can be one of the special keyring IDs listed under KEYCTL_GET_KEYRING_ID(2const). cute little shortcut, iykyk. π¦
π«Ά RETURN VALUE
- On success: the ID of the key that was found. found it, bestie!! π₯
- On error:
-1is returned, anderrnois set to indicate the error. π
π ERRORS
EINVALβ the size of the description indesc(including the terminating null byte) exceeded 4096 bytes. too long, babe. the description overflowed. π
π VERSIONS
There's a wrapper for this in the libkeyutils library: keyctl_search(3). use the wrapper, it's lowkey nicer. β¨
β STANDARDS
Linux. π§
π§ HISTORY
Linux 2.6.10. vintage but valid. π
π SEE ALSO
mwah π that's the whole page, from the KEYCTL_SEARCH(2const) header at the top to the footer down at the bottom β Linux man-pages 6.20, dated 2026-02-08. go find ur key, bestie, u 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