LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   chmod question (https://www.linuxquestions.org/questions/linux-newbie-8/chmod-question-466376/)

curtisf14 07-21-2006 06:32 PM

chmod question
 
I have a quick question about chmod. I want the user "nobody" to be able to execute a script I wrote with the user ID set to mine, so I used chmod to change the file permissions:
Code:

chmod u+s myfile
However, it appears that if I call commands from within the script, my user ID no longer is set for that command (I assume it defaults back to "nobody", but I'm not sure). Is there any way to get my user ID to pass down to other commands in the script? Or is there another way to do this altogether?

twantrd 07-21-2006 06:41 PM

If you do that, you are allowing the owner of the file to execute a program as 'root'. If you want the user 'nobody' to execute the program as the owner, then you need the setgid bit set and put 'nobody' in the group.

Not only that, setuids and setgids do not work for shell scripts. So, if yours is, it won't work. It needs to be a real executable, a compiled program.

-twantrd

curtisf14 07-21-2006 07:05 PM

Yes, the file is a bash script. I thought that if the setuid bit is set, then any user executing the script will have the same permissions as the owner of the file. Is this not true? Maybe I would need to change the permissions on "bash", but that's probably not a good idea. Do I need to write an equivalent script in C and compile it?

twantrd 07-21-2006 09:50 PM

Quote:

I thought that if the setuid bit is set, then any user executing the script will have the same permissions as the owner of the file. Is this not true?
My apologies. Yes, if the setuid bit is set, the program will run as the OWNER.

Quote:

Do I need to write an equivalent script in C and compile it?
Yes.

-twantrd

curtisf14 07-23-2006 03:05 AM

Awesome, thanks. Off to write that C script... :-)


All times are GMT -5. The time now is 02:09 AM.