initgroups(3)

๐Ÿ’– initgroups โ€” the glibc manual page, but make it cute ๐Ÿ’–

okay bestie, so this one lives in the Library Functions Manual (section 3, the libc girlies ๐ŸŒธ). It's called initgroups, and it's the little function that sorts out your supplementary group access list. Yes it's giving sysadmin. Yes it's important. Let's go ๐Ÿซถ


โœจ NAME โœจ

initgroups โ€” initialize the supplementary group access list


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc)


๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

#include <sys/types.h>
#include <grp.h>

int initgroups(const char *user, gid_t group);

๐ŸŽ€ Feature Test Macro Requirements for glibc ๐ŸŽ€

(see feature_test_macros(7))

initgroups():

  • Since glibc 2.19: _DEFAULT_SOURCE
  • glibc 2.19 and earlier: _BSD_SOURCE

periodt, those are the macros you need, no cap ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so here's the vibe. initgroups() initializes the group access list. The way it does that is it reads the group database โ€” that's /etc/group, iconic file, we love her โ€” and it uses all the groups of which user is a member. So it's basically doing your group homework for you ๐Ÿ“โœจ

And then, as a lil bonus treat, the additional group group is also added to the list. Extra. Very main character of it, honestly ๐Ÿ’…

โš ๏ธ heads up bestie: the user argument must be non-NULL. Like, must. Don't be sending a NULL in there, that's not the move ๐Ÿšซ

๐Ÿ’€ RETURN VALUE ๐Ÿ’€

  • On success: initgroups() returns 0 ๐ŸŽ‰ slay
  • On error: it returns -1, and errno gets set to tell you what went wrong (iykyk, always check your errno)

๐Ÿ™ˆ ERRORS ๐Ÿ™ˆ

  • ENOMEM โ€” not enough memory to allocate the group information structure ๐Ÿ˜ญ the malloc girlies are struggling
  • EPERM โ€” the calling process has insufficient privilege. Peep the underlying system call setgroups(2) for the full tea โ˜•

๐Ÿ“ FILES ๐Ÿ“

  • /etc/group โ€” the group database file, the source of truth, the blueprint ๐Ÿ’–

โญ ATTRIBUTES โญ

For an explanation of the terms used in this section, see attributes(7).

  • Interface: initgroups()
  • Attribute: Thread safety
  • Value: MT-Safe locale

no table bestie, we do bullets here, but the facts are the facts: initgroups() is thread-safe with respect to locale ๐Ÿงš


๐Ÿ‘‘ STANDARDS ๐Ÿ‘‘

None. Literally none. It's just out here doing its own thing, unstandardized and unbothered ๐Ÿ’…


๐ŸŒธ HISTORY ๐ŸŒธ

SVr4, 4.3BSD. Ancient. Vintage. A true icon of the ages ๐Ÿ›๏ธโœจ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ


and that's the whole page bestie, go forth and initialize those groups ๐Ÿซถ๐ŸŒˆโญ

signed off with love: this is from Linux man-pages 6.20, dated 2026-02-08 โ€” catch you in the next manpage, 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