setuid bit result
I have a shell script that I want to s开发者_开发问答et uid bit. I set the owner to root and set uid bit. I added 'whoami'in the shell to check if it is working properly but when I executed the script, whoami returned user's name, not root. Then this is wrong, right? I should have gotten root if uid was set correctly, right?
No, the setuid bit does NOT change the logged in user, it changes the effective user (euid) the script runs as.
Furthermore, setuid bits do not work on scripts.
If you want a script to be executed as root by less privileged users, I recommend to look into "su" or "sudo".
You can't use the setuid bit with shell scripts. The shell parses the shebang line to determine the program to execute, then launches that program without caring the slightest about the setuid bit set on the script.
See https://serverfault.com/questions/8449/cannot-set-uid-on-shell-scripts.
精彩评论