Question

I have the following "root-file" with the following contents:

$ cat root-file 
#!/bin/bash   
echo $EUID
id

Following are the permissions for this file:

$ ls -l root-file 
-rwsr-sr-x 1 root root 15 Nov 18 02:20 root-file

Since the set-user-id bit is set for this file, I would expect that on executing this file, the effective uid would be displayed as 0 even when a non-root user executes it (since set-user-id bit causes the process to be executed with the effective user-id of the owner of the file, which in this case is root). However, instead I get the following output on executing "root-file" from a non-root shell.

$ ./root-file 
1000
uid=1000(chanakya) gid=1000(chanakya) groups=1000(chanakya),4(adm),20(dialout),24(cdrom),46(plugdev),105(lpadmin),119(admin),122(sambashare)

This file/or script is not being executed with effective user-id 0. Why is that so?

Was it helpful?

Solution

you cannot use setuid on shell scripts...

if you absolutely need to use setuid checkout http://isptools.sourceforge.net/suid-wrap.html

Normally something like this could also be established using some custom sudo configuration...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top