1 .\" Copyright (C), 1994, Graeme W. Wilford. (Wilf.)
2 .\" and Copyright (C) 2010, 2015, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Fri Jul 29th 12:56:44 BST 1994 Wilf. <G.Wilford@ee.surrey.ac.uk>
27 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified 2002-03-09 by aeb
30 .TH SETGID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
32 setgid \- set group identity
35 .B #include <unistd.h>
37 .BI "int setgid(gid_t " gid );
41 sets the effective group ID of the calling process.
42 If the calling process is privileged (more precisely: has the
44 capability in its user namespace),
45 the real GID and saved set-group-ID are also set.
49 is implemented like the POSIX version with the
52 This allows a set-group-ID program that is not set-user-ID-root
53 to drop all of its group
54 privileges, do some un-privileged work, and then reengage the original
55 effective group ID in a secure manner.
57 On success, zero is returned.
58 On error, \-1 is returned, and
60 is set to indicate the error.
64 The group ID specified in
66 is not valid in this user namespace.
69 The calling process is not privileged (does not have the
70 \fBCAP_SETGID\fP capability in its user namespace), and
72 does not match the real group ID or saved set-group-ID of
75 POSIX.1-2001, POSIX.1-2008, SVr4.
79 system call supported only 16-bit group IDs.
80 Subsequently, Linux 2.4 added
82 supporting 32-bit IDs.
85 wrapper function transparently deals with the variation across kernel versions.
87 .SS C library/kernel differences
88 At the kernel level, user IDs and group IDs are a per-thread attribute.
89 However, POSIX requires that all threads in a process
90 share the same credentials.
91 The NPTL threading implementation handles the POSIX requirements by
92 providing wrapper functions for
93 the various system calls that change process UIDs and GIDs.
94 These wrapper functions (including the one for
96 employ a signal-based technique to ensure
97 that when one thread changes credentials,
98 all of the other threads in the process also change their credentials.
105 .BR capabilities (7),
107 .BR user_namespaces (7)