0

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?

gjain
  • 4,468
  • 5
  • 39
  • 47
  • Does root own the file? The SUID bit sets the user ID to that of its owner, who is not necessarily root (although most SUID programs are owned by root for that reason). –  Nov 18 '12 at 01:49
  • Yes, root owns the file. See the output of "ls -l root-file". – gjain Nov 18 '12 at 01:55

1 Answers1

1

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...

André Keller
  • 3,179
  • 3
  • 15
  • 23