KEYCTL_CHOWN(2const)
π
KEYCTL_CHOWN (the 2const one, bestie)
okay so. this is KEYCTL_CHOWN, and it's literally just "change the ownership of a key". that's it. that's the whole vibe. it lives in the 2const section, which is the little corner of the manual where all the keyctl sub-commands hang out. π
β¨ NAME β¨
KEYCTL_CHOWN β change the ownership of a key π
π 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_CHOWN, key_serial_t key,
uid_t uid, gid_t gid);
like, yes, you're calling syscall(2) directly because it's giving raw-kernel-energy today π
πΈ DESCRIPTION πΈ
Change the ownership (user and group ID) of a key. that's the whole thing. you're handing someone else the keys to the key. iconic.
keycontains the key ID. π which key we're messing withuidcontains the new user ID β or-1in case the user ID shouldn't be changed. so-1is the "no thank u, leave it" option π«gidcontains the new group ID β or-1in case the group ID shouldn't be changed. same deal,-1means "don't touch" π
The key must grant the caller setattr permission. no permission, no chown, no exceptions, periodt. π
For the UID to be changed, or for the GID to be changed to a group the caller is not a member of, the caller must have the CAP_SYS_ADMIN capability (see capabilities(7)). so if you're out here trying to hand your key to a group you're not even in, you better be root-ish, bestie. π
If the UID is to be changed, the new user must have sufficient quota to accept the key. π and the quota deduction will be removed from the old user and moved to the new user should the UID be changed. the accounting literally follows the key around like a little luggage tag. π§³
β RETURN VALUE β
- On success,
0is returned. slay. π - On error,
-1is returned, anderrnois set to indicate the error. π
π¦ VERSIONS π¦
A wrapper is provided in the libkeyutils library: keyctl_chown(3). so if you don't wanna raw-dog the syscall, there's a whole cozy little function for you in libkeyutils. π«Ά
π STANDARDS π
Linux. just Linux. that's the standard. π§
π HISTORY π
Linux 2.6.10. ancient in kernel years, still eating. π₯
π SEE ALSO π
β οΈ quick vibe check:-1foruidorgidmeans "don't change this one" β do not pass-1thinking it's a real ID. and remember thesetattrpermission +CAP_SYS_ADMINrules, because the kernel does not do vibes-based access control. π§
k that's the whole page, ily, go chown responsibly π
Linux man-pages 6.20, dated 2026-02-08 β that's the source/version energy this page is pulling from, mwah π
π¦ 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