1seteuid(2)                    System Calls Manual                   seteuid(2)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

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

STANDARDS

73       POSIX.1-2008.
74

HISTORY

76       POSIX.1-2001, 4.3BSD.
77

SEE ALSO

79       geteuid(2), setresuid(2), setreuid(2), setuid(2), capabilities(7), cre‐
80       dentials(7), user_namespaces(7)
81
82
83
84Linux man-pages 6.05              2023-03-30                        seteuid(2)
Impressum