UID/GID on Executable: Effective vs. Real UID concept

Posted on 2010-09-15
Last Modified: 2012-05-10
I wrote a short C++ program that only receives an input value (basically cin >> a ;).  I enabled UID on it.  So ls -l shows:
-rwsr-xr-x 1 root root   6058 Sep 15 09:50 prog

Now I executed it as "test" user and checked the real vs. effective UID as under:
 ps -eo cmd,ruser,euser,ruid,euid,pid | grep prog | grep -v grep
./prog                      test     root       501     0 14251

Just as I expected, real userid is 501(test) and effective uid is 0(root).

So far so good.

Now I tried to do the same using a shell script.  A bash script called script which should do the same thing but it doesn't.  Why?  Is there a way to see it working in a shell script.

-rwsr-xr-x 1 root root      5 Sep 15 09:29 script

ps -eo cmd,ruser,euser,ruid,euid,pid | grep 14328
bash                        test     test       501   501 14328

Second, will the script work as root or as user test?
Question by:farzanj
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 68

Accepted Solution

woolmilkporc earned 450 total points
ID: 33682601
On most Unixes the "setuid on execution" flag does not work for shell scripts, only for binary executables.
Since this seems to be the case with your OS,  your script will run as user test.


Assisted Solution

jlar310 earned 50 total points
ID: 33682645
bash (and other shells) ignores the setuid bit by design. It's a security thing. The setuid bit only works on compiled binary programs. In your example, the script will always run as the logged in user.
LVL 31

Author Comment

ID: 33682704
I ran it on Red Hat Linux (RHEL5.5).
Second, please clarify if effective uid/gid the one that is checked for determining the access/permissions.  Does real uid/gid ever matter at all?
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

LVL 68

Assisted Solution

woolmilkporc earned 450 total points
ID: 33682870
The real userid always remains unchanged, and can be tracked by a so-designed application to find out the id of the invoking user.
The real id is used e.g. when files are being created by means of a setuid program, to set ownership to the correct id.
Besides that this real id can of course be used to possibly reject some actions otherwise allowed for the "effective" userid.
Think of /usr/bin/passwd! This executable is setuid "root" to allow for changing one's own password, but it checks the "real" id to reject changes for other users if not invoked by root.
LVL 68

Assisted Solution

woolmilkporc earned 450 total points
ID: 33682931
... and yes, RHEL does not honor setuid! It's Linux, and that functionality is built into the Linux kernel, afaik.
LVL 68

Assisted Solution

woolmilkporc earned 450 total points
ID: 33682950
The above should read
"...  does not honor setuid for shell scripts ..."
of course.
LVL 31

Author Closing Comment

ID: 33683100
Thank you so much for your clarification and your time.  Appreciated.

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Recently, an awarded photographer, Selina De Maeyer (, completed a photo shoot of a beautiful event ( in An…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question