1SETUID(2) Linux Programmer's Manual SETUID(2)
2
3
4
6 setuid - set user identity
7
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 int setuid(uid_t uid);
13
15 setuid() sets the effective user ID of the calling process. If the
16 effective UID of the caller is root, the real UID and saved set-user-ID
17 are also set.
18
19 Under Linux, setuid() is implemented like the POSIX version with the
20 _POSIX_SAVED_IDS feature. This allows a set-user-ID (other than root)
21 program to drop all of its user privileges, do some un-privileged work,
22 and then reengage the original effective user ID in a secure manner.
23
24 If the user is root or the program is set-user-ID-root, special care
25 must be taken. The setuid() function checks the effective user ID of
26 the caller and if it is the superuser, all process-related user ID's
27 are set to uid. After this has occurred, it is impossible for the pro‐
28 gram to regain root privileges.
29
30 Thus, a set-user-ID-root program wishing to temporarily drop root priv‐
31 ileges, assume the identity of an unprivileged user, and then regain
32 root privileges afterwards cannot use setuid(). You can accomplish
33 this with seteuid(2).
34
36 On success, zero is returned. On error, -1 is returned, and errno is
37 set appropriately.
38
40 EAGAIN The uid does not match the current uid and uid brings process
41 over its RLIMIT_NPROC resource limit.
42
43 EPERM The user is not privileged (Linux: does not have the CAP_SETUID
44 capability) and uid does not match the real UID or saved set-
45 user-ID of the calling process.
46
48 SVr4, POSIX.1-2001. Not quite compatible with the 4.4BSD call, which
49 sets all of the real, saved, and effective user IDs.
50
52 Linux Notes
53 Linux has the concept of file system user ID, normally equal to the
54 effective user ID. The setuid() call also sets the file system user ID
55 of the calling process. See setfsuid(2).
56
57 If uid is different from the old effective uid, the process will be
58 forbidden from leaving core dumps.
59
61 getuid(2), seteuid(2), setfsuid(2), setreuid(2), capabilities(7), cre‐
62 dentials(7)
63
65 This page is part of release 3.25 of the Linux man-pages project. A
66 description of the project, and information about reporting bugs, can
67 be found at http://www.kernel.org/doc/man-pages/.
68
69
70
71Linux 2010-02-21 SETUID(2)