1 .\" Copyright (C), 1994, Graeme W. Wilford (Wilf).
2 .\" and Copyright (C) 2010, 2014, 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 .\" Changes inspired by patch from Richard Kettlewell
28 .\" <richard@greenend.org.uk>, aeb 970616.
29 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" Added notes on capability requirements
31 .TH SETUID 2 2015-07-23 "Linux" "Linux Programmer's Manual"
33 setuid \- set user identity
35 .B #include <sys/types.h>
37 .B #include <unistd.h>
39 .BI "int setuid(uid_t " uid );
42 sets the effective user ID of the calling process.
43 If the calling process is prvileged
44 (more precisely: if the process has the
47 the real UID and saved set-user-ID are also set.
51 is implemented like the POSIX version with the
54 This allows a set-user-ID (other than root) program to drop all of its user
55 privileges, do some un-privileged work, and then reengage the original
56 effective user ID in a secure manner.
58 If the user is root or the program is set-user-ID-root, special care must be
62 function checks the effective user ID of the caller and if it is
63 the superuser, all process-related user ID's are set to
65 After this has occurred, it is impossible for the program to regain root
68 Thus, a set-user-ID-root program wishing to temporarily drop root
69 privileges, assume the identity of an unprivileged user, and then regain
70 root privileges afterward cannot use
72 You can accomplish this with
75 On success, zero is returned.
76 On error, \-1 is returned, and
83 can fail even when the caller is UID 0;
84 it is a grave security error to omit checking for a failure return from
89 The call would change the caller's real UID (i.e.,
91 does not match the caller's real UID),
92 but there was a temporary failure allocating the
93 necessary kernel data structures.
97 does not match the real user ID of the caller and this call would
98 bring the number of processes belonging to the real user ID
103 Since Linux 3.1, this error case no longer occurs
104 (but robust applications should check for this error);
105 see the description of
111 The user ID specified in
113 is not valid in this user namespace.
116 The user is not privileged (Linux: does not have the
120 does not match the real UID or saved set-user-ID of the calling process.
122 POSIX.1-2001, POSIX.1-2008, SVr4.
123 Not quite compatible with the 4.4BSD call, which
124 sets all of the real, saved, and effective user IDs.
125 .\" SVr4 documents an additional EINVAL error condition.
127 Linux has the concept of the filesystem user ID, normally equal to the
131 call also sets the filesystem user ID of the calling process.
137 is different from the old effective UID, the process will
138 be forbidden from leaving core dumps.
142 system call supported only 16-bit user IDs.
143 Subsequently, Linux 2.4 added
145 supporting 32-bit IDs.
148 wrapper function transparently deals with the variation across kernel versions.
150 .SS C library/kernel differences
151 At the kernel level, user IDs and group IDs are a per-thread attribute.
152 However, POSIX requires that all threads in a process
153 share the same credentials.
154 The NPTL threading implementation handles the POSIX requirements by
155 providing wrapper functions for
156 the various system calls that change process UIDs and GIDs.
157 These wrapper functions (including the one for
159 employ a signal-based technique to ensure
160 that when one thread changes credentials,
161 all of the other threads in the process also change their credentials.
169 .BR capabilities (7),
171 .BR user_namespaces (7)