KEYCTL_SETPERM(3)
π keyctl_setperm β like, the key permission glow-up page
okay bestie, pull up a chair π«Ά this is keyctl_setperm(3), one of the Linux Key Management Calls, and it's genuinely so useful. no cap.
β¨ NAME β¨
keyctl_setperm β change the permissions mask on a key π
πΈ SYNOPSIS πΈ
#include <keyutils.h>
long keyctl_setperm(key_serial_t key, key_perm_t perm);
π DESCRIPTION π
keyctl_setperm() changes the permissions mask on a key. that's the whole vibe. it's giving "who gets to do what with this key" β¨
now. plot twist. a process that does not have the SysAdmin capability may not change the permissions mask on a key that doesn't have the same UID as the caller. so if it's not your key and you're not sysadmin-coded, hands off bestie π
also, the caller must have setattr permission on a key to be able to change its permissions mask. like, you need the pass to change the pass. iykyk π
the permissions mask is a bitwise-OR of the following flags:
KEY_xxx_VIEWβ grant permission to view the attributes of a key. peek at the metadata, not the payload πKEY_xxx_READβ grant permission to read the payload of a key or to list a keyring πKEY_xxx_WRITEβ grant permission to modify the payload of a key or to add or remove links to/from a keyring βοΈKEY_xxx_SEARCHβ grant permission to find a key or to search a keyring πKEY_xxx_LINKβ grant permission to make links to a key πKEY_xxx_SETATTRβ grant permission to change the ownership and permissions attributes of a key π οΈKEY_xxx_ALLβ grant all the above. the whole menu, no substitutions π
the xxx in the above should be replaced by one of:
POSβ grant the permission to a process that possesses the key (has it attached searchably to one of the process's keyrings). the main character category πUSRβ grant the permission to a process with the same UID as the key.GRPβ grant the permission to a process with the same GID as the key, or with a match for the key's GID amongst that process's Groups list.OTHβ grant the permission to any other process. everyone else, come on in π
examples include: KEY_POS_VIEW, KEY_USR_READ, KEY_GRP_SEARCH and KEY_OTH_ALL. see how the pattern goes? KEY_ + category + _ + action. slay β¨
okay this next part is the part people get wrong, so listen up fr fr:
user, group and other grants are exclusive: if a process qualifies in the user category, it will not qualify in the groups category; and if a process qualifies in either user or groups then it will not qualify in the other category. it's giving strict clique rules β you're in one lane, not all of them π
possessor grants are cumulative with the grants from the user, groups and other categories. so POS stacks on top of whatever else you got π«Ά
β RETURN VALUE β
on success keyctl_setperm() returns 0. on error, the value -1 will be returned and errno will have been set to an appropriate error. classic. π
π₯ ERRORS π₯
ENOKEYβ the specified key does not exist. it's not there bestie, it never was πEKEYEXPIREDβ the specified key has expired. it had its moment, and its moment is over β³EKEYREVOKEDβ the specified key has been revoked. cancelled, literally π«EACCESβ the named key exists, but does not grantsetattrpermission to the calling process. the key is right there and it's still not letting you in π
π§ LINKING π§
this is a library function that can be found in libkeyutils. when linking, -lkeyutils should be specified to the linker. don't forget it, or the linker will simply not know her π
π¦ SEE ALSO π¦
keyctl(1), add_key(2), keyctl(2), request_key(2), keyctl(3), keyrings(7), keyutils(7)
and that's the whole page, bestie. go forth and set some perms responsibly π
this one came out of the Linux corner of the world, dated 4 May 2006, and it lives at KEYCTL_SETPERM(3) in the manual. 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 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