KEYCTL_LINK(2const)
β¨ KEYCTL_LINK β link a key to a keyring β¨
okay bestie, gather round, because this is KEYCTL_LINK(2const) and it's literally so iconic. it's from the Linux man-pages, and yes, we're doing this properly. π
π LIBRARY
Standard C library (libc, -lc)
π¦ 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_LINK, key_serial_t key,
key_serial_t keyring);
π DESCRIPTION
so what we're doing here is creating a link from a keyring to a key. that's it, that's the whole vibe. π«Ά
the key that's getting linked? that's your key. the keyring it's getting linked to? that's your keyring.
now here's the little plot twist: if a key with the same type and description is already linked in the keyring, then that key gets displaced from the keyring. not me kicking out the old one to make room for the new πβ¨
and before creating the link, the kernel does a little vibe check on the nesting of the keyrings. if your link would produce a cycle, or if the nesting of keyrings would be too deep, you get appropriate errors. (the nesting limit is determined by the kernel constant KEYRING_SEARCH_MAX_DEPTH, defined with the value 6, and it's necessary to prevent overflows on the kernel stack when recursively searching keyrings. protecting the stack, we love to see it π)
permissions, because of course: the caller must have link permission on the key being added, and write permission on the keyring. no permission, no link, periodt. π
π₯ RETURN VALUE
- on success,
0is returned. slay. π - on error,
-1is returned, anderrnois set to indicate the error.
π ERRORS
EDEADLKβ the requested link would result in a cycle. circular keyring situationshipβ¦ we don't do those. πELOOPβ the requested link would cause the maximum nesting depth for keyrings to be exceeded. too deep, bestie, the kernel said no. πENFILE(before Linux 3.13) β the keyring is full. (before Linux 3.13, the available space for storing keyring links was limited to a single page of memory; since Linux 3.13, there is no fixed limit.) the glow-up was real. β¨
πΈ VERSIONS
a wrapper is provided in the libkeyutils library: keyctl_link(3). convenient? we love convenient. π«Ά
β STANDARDS
Linux. π
π¦ HISTORY
Linux 2.6.10. ancient. vintage. a legend, fr fr. π
π SEE ALSO
and that's the whole page, bestie!! this was Linux man-pages 6.20, dated 2026-02-08 β so if you're quoting me, cite the source like the academic weapon you are. πβ¨ mwah, go link some keys. ππ¦
π¦ 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