| 1 |
.\" Copyright 2001, Andries E. Brouwer <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH seteuid 2 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
seteuid, setegid \- set effective user or group ID |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <unistd.h> |
| 15 |
.P |
| 16 |
.BI "int seteuid(uid_t " euid ); |
| 17 |
.BI "int setegid(gid_t " egid ); |
| 18 |
.fi |
| 19 |
.P |
| 20 |
.RS -4 |
| 21 |
Feature Test Macro Requirements for glibc (see |
| 22 |
.BR feature_test_macros (7)): |
| 23 |
.RE |
| 24 |
.P |
| 25 |
.BR seteuid (), |
| 26 |
.BR setegid (): |
| 27 |
.nf |
| 28 |
_POSIX_C_SOURCE >= 200112L |
| 29 |
|| /* glibc <= 2.19: */ _BSD_SOURCE |
| 30 |
.fi |
| 31 |
.SH DESCRIPTION |
| 32 |
.BR seteuid () |
| 33 |
sets the effective user ID of the calling process. |
| 34 |
Unprivileged processes may only set the effective user ID to the |
| 35 |
real user ID, the effective user ID or the saved set-user-ID. |
| 36 |
.P |
| 37 |
Precisely the same holds for |
| 38 |
.BR setegid () |
| 39 |
with "group" instead of "user". |
| 40 |
.\" When |
| 41 |
.\" .I euid |
| 42 |
.\" equals \-1, nothing is changed. |
| 43 |
.\" (This is an artifact of the implementation in glibc of seteuid() |
| 44 |
.\" using setresuid(2).) |
| 45 |
.SH RETURN VALUE |
| 46 |
On success, zero is returned. |
| 47 |
On error, \-1 is returned, and |
| 48 |
.I errno |
| 49 |
is set to indicate the error. |
| 50 |
.P |
| 51 |
.IR Note : |
| 52 |
there are cases where |
| 53 |
.BR seteuid () |
| 54 |
can fail even when the caller is UID 0; |
| 55 |
it is a grave security error to omit checking for a failure return from |
| 56 |
.BR seteuid (). |
| 57 |
.SH ERRORS |
| 58 |
.TP |
| 59 |
.B EINVAL |
| 60 |
The target user or group ID is not valid in this user namespace. |
| 61 |
.TP |
| 62 |
.B EPERM |
| 63 |
In the case of |
| 64 |
.BR seteuid (): |
| 65 |
the calling process is not privileged (does not have the |
| 66 |
.B CAP_SETUID |
| 67 |
capability in its user namespace) and |
| 68 |
.I euid |
| 69 |
does not match the current real user ID, current effective user ID, |
| 70 |
or current saved set-user-ID. |
| 71 |
.IP |
| 72 |
In the case of |
| 73 |
.BR setegid (): |
| 74 |
the calling process is not privileged (does not have the |
| 75 |
.B CAP_SETGID |
| 76 |
capability in its user namespace) and |
| 77 |
.I egid |
| 78 |
does not match the current real group ID, current effective group ID, |
| 79 |
or current saved set-group-ID. |
| 80 |
.SH VERSIONS |
| 81 |
Setting the effective user (group) ID to the |
| 82 |
saved set-user-ID (saved set-group-ID) is |
| 83 |
possible since Linux 1.1.37 (1.1.38). |
| 84 |
On an arbitrary system one should check |
| 85 |
.BR _POSIX_SAVED_IDS . |
| 86 |
.P |
| 87 |
Under glibc 2.0, |
| 88 |
.BI seteuid( euid ) |
| 89 |
is equivalent to |
| 90 |
.BI setreuid(\-1, " euid" ) |
| 91 |
and hence may change the saved set-user-ID. |
| 92 |
Under glibc 2.1 and later, it is equivalent to |
| 93 |
.BI setresuid(\-1, " euid" ", \-1)" |
| 94 |
and hence does not change the saved set-user-ID. |
| 95 |
Analogous remarks hold for |
| 96 |
.BR setegid (), |
| 97 |
with the difference that the change in implementation from |
| 98 |
.BI setregid(\-1, " egid" ) |
| 99 |
to |
| 100 |
.BI setresgid(\-1, " egid" ", \-1)" |
| 101 |
occurred in glibc 2.2 or 2.3 (depending on the hardware architecture). |
| 102 |
.P |
| 103 |
According to POSIX.1, |
| 104 |
.BR seteuid () |
| 105 |
.RB ( setegid ()) |
| 106 |
need not permit |
| 107 |
.I euid |
| 108 |
.RI ( egid ) |
| 109 |
to be the same value as the current effective user (group) ID, |
| 110 |
and some implementations do not permit this. |
| 111 |
.SS C library/kernel differences |
| 112 |
On Linux, |
| 113 |
.BR seteuid () |
| 114 |
and |
| 115 |
.BR setegid () |
| 116 |
are implemented as library functions that call, respectively, |
| 117 |
.BR setresuid (2) |
| 118 |
and |
| 119 |
.BR setresgid (2). |
| 120 |
.SH STANDARDS |
| 121 |
POSIX.1-2024. |
| 122 |
.SH HISTORY |
| 123 |
POSIX.1-2001, 4.3BSD. |
| 124 |
.SH SEE ALSO |
| 125 |
.BR geteuid (2), |
| 126 |
.BR setresuid (2), |
| 127 |
.BR setreuid (2), |
| 128 |
.BR setuid (2), |
| 129 |
.BR capabilities (7), |
| 130 |
.BR credentials (7), |
| 131 |
.BR user_namespaces (7) |