Search code examples
linuxsudomountsticky

mount without sudo using sticky bit?


I am trying to write a shell script to mount loop device, and I am assigning this script with a sticky bit to execute as uid(root).(this is for other users on server) The problem is I can't seem to run 'mount' command without using sudo in front of it. When I am in root account, I can run 'mount' command without any issue, so I thought by setting script with rws-r_x-r_x would do it.

Am I misunderstanding the concept of using sticky bit? or is there any other way?

The server is running under Ubuntu 10.04


Solution

  • You mean the setuid bit, not the sticky one. The kernel doesn't honor the setuid bit on scripts. See this post for a thorough description, here's a summary: the gist is that suid on a script is insecure.* The kernel starts reading the script to execute it, but it sees the #!/path/to/interpreter and figures out that it needs to be interpreted. It then cancels "executing" the script directly and calls the specified interpreter, passing the script name as the first argument (and all subsequent arguments in order after that). The reason setting UID is insecure in this instance is that an attacker could potentially change the script to be executed between the kernel setting the new UID and the interpreter reading the file.

    *: The other post mentioned that perl handles its scripts in such a way that they can be suid.


    As for the actual mounting problem at hand, add a line to /etc/fstab/ and include the user option.