It might be a silly question but I am not understanding EUID
and UID
correctly.
The description of real ID and effective ID is clear and I get it. Based on what I have found on Google and ebooks, when using su
, sudo
or SUID
, effective ID should change. Also, to my understanding UID
in Bash should contain real ID and EUID
should contain effective ID.
My assumption is EUID
and UID
should be different when I am using su
, sudo
or SUID
but whenever I try echo $EUID
and echo $UID
the result of both are the same.
Also, I tried id -u
and id -r -u
and again they are always the same.
Could someone explain to me at when and what situation exactly $EUID
and $UID
are different?
By default bash drops the privileges. There is a special privileged mode set -p
.
# copy bash executable
$ sudo cp /usr/bin/bash ./bash
# set the suid mode
$ chmod +s ./bash
$ ls -l bash
-rwsr-sr-x 1 root root 903504 05-29 23:48 ./bash*
# run it
$ ./bash -p -c 'echo $UID $EUID'
1000 0