Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between EUID and UID?

Tags:

EUID is not the same as UID. At what context are these both are used in the script?

I tried to get the values by echo "UID is $UID and EUID is $EUID", but only space came as output. My machine runs Ubuntu 12.04 LTS. Seen at some sites that this is usually used to check whether it is root user and all but not able to get proper difference.

like image 628
Arun Chettoor Avatar asked Dec 27 '14 17:12

Arun Chettoor


People also ask

What is EUID used for?

Effective user ID The effective UID ( euid ) of a process is used for most access checks. It is also used as the owner for files created by that process.

What is EUID of a process?

EUID is the Effective User ID. The effective user ID describes the user whose file access permissions are used by the process. RUID is the Real User ID. The real user ID identifies the user who created the process.

What does EUID mean in Linux?

EUID(Effective User ID) Generally, UID and EUID is the same. EUID is changed by executable file that is configured SetUID authority. EUID temporarily stores another account's UID. The authority of a process is determined according to the UID stored in the EUID.

What is the EUID of root user?

Users created by root have euid=0(root) egid=2(bin)!!! - Operating Systems.


2 Answers

They're different when a program is running set-uid. Effective UID is the user you changed to, UID is the original user.

like image 178
Barmar Avatar answered Oct 19 '22 01:10

Barmar


It only works on bash, not in dash (in Debian based distros as Ubuntu sh is usually a symlink to dash).

If you are running the script interactively you might not have bash configured as your default shell, run bash before trying.

If you are running it from console:

bash script.sh 

If you are running it using its path (for example ./script.sh) ensure the first line of the script is:

#!/bin/bash 

And not:

#!/bin/sh 

For a more generic way to do it check: https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root

In that post the command id is mentioned, where:

id -u    # is the EUID id -u -r # is the UID 
like image 20
Fernando Avatar answered Oct 19 '22 00:10

Fernando