1SETEUID(2)                 Linux Programmer's Manual                SETEUID(2)
2
3
4

NAME

6       seteuid, setegid - set effective user or group ID
7

SYNOPSIS

9       #include <unistd.h>
10
11       int seteuid(uid_t euid);
12       int setegid(gid_t egid);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       seteuid(), setegid():
17           _POSIX_C_SOURCE >= 200112L
18               || /* Glibc <= 2.19: */ _BSD_SOURCE
19

DESCRIPTION

21       seteuid()  sets the effective user ID of the calling process.  Unprivi‐
22       leged processes may only set the effective user ID to the real user ID,
23       the effective user ID or the saved set-user-ID.
24
25       Precisely the same holds for setegid() with "group" instead of "user".
26

RETURN VALUE

28       On  success,  zero is returned.  On error, -1 is returned, and errno is
29       set to indicate the error.
30
31       Note: there are cases where seteuid() can fail even when the caller  is
32       UID  0; it is a grave security error to omit checking for a failure re‐
33       turn from seteuid().
34

ERRORS

36       EINVAL The target user or group ID is not valid in this user namespace.
37
38       EPERM  In the case of seteuid(): the calling process is not  privileged
39              (does  not have the CAP_SETUID capability in its user namespace)
40              and euid does not match the current real user ID, current effec‐
41              tive user ID, or current saved set-user-ID.
42
43              In  the case of setegid(): the calling process is not privileged
44              (does not have the CAP_SETGID capability in its user  namespace)
45              and  egid  does not match the current real group ID, current ef‐
46              fective group ID, or current saved set-group-ID.
47

CONFORMING TO

49       POSIX.1-2001, POSIX.1-2008, 4.3BSD.
50

NOTES

52       Setting the effective user (group) ID to the saved  set-user-ID  (saved
53       set-group-ID) is possible since Linux 1.1.37 (1.1.38).  On an arbitrary
54       system one should check _POSIX_SAVED_IDS.
55
56       Under glibc 2.0, seteuid(euid) is equivalent to setreuid(-1, euid)  and
57       hence  may change the saved set-user-ID.  Under glibc 2.1 and later, it
58       is equivalent to setresuid(-1, euid, -1) and hence does not change  the
59       saved set-user-ID.  Analogous remarks hold for setegid(), with the dif‐
60       ference that the change in implementation from  setregid(-1,  egid)  to
61       setresgid(-1,  egid, -1) occurred in glibc 2.2 or 2.3 (depending on the
62       hardware architecture).
63
64       According to POSIX.1, seteuid() (setegid()) need not permit euid (egid)
65       to be the same value as the current effective user (group) ID, and some
66       implementations do not permit this.
67
68   C library/kernel differences
69       On Linux, seteuid() and setegid() are implemented as library  functions
70       that call, respectively, setreuid(2) and setregid(2).
71

SEE ALSO

73       geteuid(2), setresuid(2), setreuid(2), setuid(2), capabilities(7), cre‐
74       dentials(7), user_namespaces(7)
75

COLOPHON

77       This page is part of release 5.13 of the Linux  man-pages  project.   A
78       description  of  the project, information about reporting bugs, and the
79       latest    version    of    this    page,    can     be     found     at
80       https://www.kernel.org/doc/man-pages/.
81
82
83
84Linux                             2021-03-22                        SETEUID(2)
Impressum