Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

setuid - set user ID

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

Optional
#include <sys/types.h>

int setuid(uid_t uid); 

Description

If the process has appropriate privileges, the setuid() function sets the real user ID, effective user ID, and the saved set-user-ID to uid.

If the process does not have appropriate privileges, but uid is equal to the real user ID or the saved set-user-ID, setuid() sets the effective user ID to uid. The real user ID and saved set-user-ID remain unchanged.

Return val.

0

–1

if successful.

if unsuccessful. errno is set to indicate the error.

Errors

setuid() will fail if:

 

 

EPERM

The process does not have appropriate privileges and uid does not match the real user ID or the saved set-user-ID.

Notes

setuid() is frequently used to relinquish privileges that are no longer needed in programs that have the s-bit for the owner set (especially root). Such programs often need the privileges granted by the s-bit only for very specific tasks. When the privileges are no longer required, they can be relinquished by a call in the form given below:

erg = setuid(getuid());

See also

setpgid(), sys/types.h, unistd.h.