In this lesson, you will learn how the Linux kernel manages process identity by allowing a running process to transition its effective UID and GID to control resource access.
The Credential Structure
Every process in Linux is associated with a cred structure inside the kernel. This structure holds the "identity" of the process: its Real UID/GID, Effective UID/GID, and Saved UID/GID. While the Real UID identifies the user who started the process, the Effective UID (EUID) is what the kernel checks whenever the process attempts to access a file or communicate with another process.
Changing Identity at Runtime
Changing these credentials at runtime allows a program to "drop" privileges after it has finished a sensitive task (like binding to a low-numbered network port) or to assume a different identity to perform a specific action.
The kernel enforces strict rules for these transitions. For instance, a process can only change its EUID to its Real UID or its Saved UID without special privileges. If a process has the CAP_SETUID capability, however, the kernel allows it to set the EUID to any arbitrary value.
Consider this conceptual flow of a privileged service:
// Process starts with root privileges (EUID 0)
// ... perform privileged initialization ...
// Drop privileges permanently to act as a standard 'web' user (UID 1001)
if (seteuid(1001) == 0) {
// The kernel updates the task's 'cred' structure.
// Future file access checks will now see UID 1001.
}
When you invoke a system call like seteuid(), the kernel verifies the request against the current process’s capability set. If approved, the kernel swaps the numeric identifier in the task’s credential object. Because this is a kernel-level update, the change is atomic and instantaneous across all threads of the process. Once the EUID is modified, every subsequent system call (like open() or connect()) will be validated against the new credentials by the kernel's permission-checking logic. This mechanism is the bedrock of the "Principle of Least Privilege," ensuring that processes run with only the power they absolutely require.
Key Takeaway: The kernel manages process identity via the cred structure, and modifying the Effective UID at runtime allows a process to dynamically restrict or expand its own access permissions without needing to restart.