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.

  • key contains the key ID. πŸ‘ˆ which key we're messing with
  • uid contains the new user ID β€” or -1 in case the user ID shouldn't be changed. so -1 is the "no thank u, leave it" option 🚫
  • gid contains the new group ID β€” or -1 in case the group ID shouldn't be changed. same deal, -1 means "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, 0 is returned. slay. πŸŽ‰
  • On error, -1 is returned, and errno is 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: -1 for uid or gid means "don't change this one" β€” do not pass -1 thinking it's a real ID. and remember the setattr permission + CAP_SYS_ADMIN rules, 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms