Real-UID:
Effective-UID:
Saved UID:
What is the idea?
At the lowest level of the operating system (the kernel), users are not identified by names, but numbers called user IDs (UID). The user ID 0 is commonly called “root”.
Each Unix process has a UID associated with it, and when trying to open a file for writing, for instance, this ID is used to determine whether the process should be granted access or not.
When you invoke the “passwd” utility, the Effective-UID of the process is set to 0, i.e. the UID of the root user. As a result, the program is permitted to modify the /etc/passwd file, and can thus replace the encrypted password in your account entry with the new one you just provided.
As a normal user, you’re only allowed to modify the password of your own account using the “passwd” utility and it doesn’t let you modify the password of any other account. So now the question is, how does the program know who invoked the utility?
That is where another UID comes in, called the Real-UID, which is used to track who the user really is. This Real-UID value is not changed when you invoke programs such as “passwd”. So the program simply needs to find out what user name corresponds to its Real-UID, and refuse to change any other account.
Normal programs, like "ls", "cat" run by a normal user under that users Real-UID. Special programs that allow user to have controlled access to protected data, can have Set-UID bit to allow the program to be run under privileged UID.
Example:
When a normal user (say "mhasan") runs the program "passwd", it starts with:
Real-UID = mhasan
Effective-UID = mhasan
Saved-UID = root
The the program (passwd) then calls a system call "seteuid ‘and since Saved-UID = 0, the call will succeed and the UIDs will be:
Real-ID = mhasan
Effective-UID = root
Saved-UID = root
After that, "passwd" process will be able to access /etc/passwd and change password for user "mhasan".