KEYCTL_LINK(3)
π KEYCTL_LINK(3) β it's giving Linux Key Management Calls β¨
okay bestie, sit down, hydrate, and let me tell you about keyctl_link and keyctl_unlink β the duo that links and unlinks a key to/from a keyring. this is from the Linux Key Management Calls manual, section 3, and it's lowkey iconic. π
πΈ NAME πΈ
keyctl_link, keyctl_unlink β link/unlink a key to/from a keyring
β¨ SYNOPSIS β¨
#include <keyutils.h>
long keyctl_link(key_serial_t key, key_serial_t keyring);
long keyctl_unlink(key_serial_t key, key_serial_t keyring);
π¦ DESCRIPTION π¦
so, two functions, two vibes. π
keyctl_link() creates a link from keyring to key. and the way that it will displace any link to another key of the same type and description in that keyring if one already exists? yeah. it said "move over, there's a new main character." periodt.
keyctl_unlink() removes the link from keyring to key β but only if it exists. no drama, just a clean break. π«Ά
now for the permissions tea, and this is important, no cap:
- the caller must have write permission on a keyring to be able to create or remove links in it.
- the caller must have link permission on a key to be able to create a link to it.
so like, you can't just barge into somebody else's keyring and start redecorating. vibe check first. π₯
β RETURN VALUE β
on success, both keyctl_link() and keyctl_unlink() return 0. slay. π
on error, the value -1 will be returned and errno will have been set to an appropriate error. it's not a vibe, but at least it tells you why.
π ERRORS π
here's the whole list, bestie, don't skip it:
ENOKEYβ The key or the keyring specified are invalid. πEKEYEXPIREDβ The key or the keyring specified have expired.EKEYREVOKEDβ The key or the keyring specified have been revoked.EACCESβ The keyring exists, but is not writable by the calling process.
and these ones are for keyctl_link() only:
ENOMEMβ Insufficient memory to expand the keyringEDQUOTβ Expanding the keyring would exceed the keyring owner's quota.EACCESβ The key exists, but is not linkable by the calling process.
yes, EACCES shows up twice. once for the keyring being unwritable, once for the key being unlinkable. two different reasons, same name, it's giving twins but make it errors. π
π LINKING π
This is a library function that can be found in libkeyutils. When linking, -lkeyutils should be specified to the linker.
that's the one. that's the flag. don't forget it or nothing links and you'll be sitting there like πβπ. iykyk.
π§ SEE ALSO π§
keyctl(1), add_key(2), keyctl(2), request_key(2), keyctl(3), keyrings(7), keyutils(7)
go read those too, they're all part of the same little friend group. π
and that's the whole page, bestie!! this one came from the Linux crew, dated 4 May 2006, and it lives under the name KEYCTL_LINK(3) in the Linux Key Management Calls manual. mwah. π
β¨
π¦ 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 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) 2006 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