-rwxr--r-- 1 root root ...... ps
This says that the user who owns it has read, write, and execute permission, and all others just read. So nobody but root can execute ps
.
The script you wrote is executable by all, but inherits the permissions from the one who invokes it, so he also gets the "permission denied" when trying to execute the ps
, as he is still a normal user.
My guess is that you want to prevent regular users from executing ps
with certain options (not that it makes sense to me), but then you have to add the setuid
bit or setgid
bit to your script (see man page of chmod
). When you do this it gets the permissions not from the invoker of the script, but from the one who owns the script.
BUT BEWARE: Setting the suid
bit on scripts is inherently insecure. You can do very much with environment variables, that e.g. tell the shell to execute commands - and then they are executed as root (here a custom c-program with the sticky bit is the better solution).
EDIT: Another solution would be to use sudo
. Here you can also configure which parameters are allowed to a sudo
ed program.
EDIT2: Why I think it is not a good idea to prohibit user just from executing ps
? As far as I know, all the information ps
outputs can be also be acquired via the /proc
system - so if you do nothing else it is just security (or whatever you want to achieve) by obfuscation.
ps
and then turn around to try and give users limited root rights for the purpose of runningps
? Not criticizing, just wondering what exactly you're trying to accomplish here -- maybe we'll figure out a better way to do itt than this... – Shadur-don't-feed-the-AI Nov 03 '11 at 14:33ps
except root;second I want to callps
indirectly via some method like calling call_ps_via_root.sh.And I can give different permission to different user by setgid to call_ps_via_root.sh – sammy Nov 04 '11 at 02:44sudo
. And possibly reexamine exactly what you intend to do and what you hope to accomplish with it, because I really fail to see how restrictingps
usage is going to help secure your system given that all it does is provide a useful interface to read out information readily available in/proc
. – Shadur-don't-feed-the-AI Nov 04 '11 at 08:25