Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I set file to be executable only to other users but not readable/writable, the reason for this I'm executing something with my username but I don't want to give out the password. I tried :

chmod 777 testfile
chown a=x
chown ugo+x

I still get permission denied when executing as another user.

share|improve this question
What about when executing it NOT as another user? And is this a script, or a binary program? Scripts must be read by the interpreter. – psusi Jul 13 '11 at 22:41

2 Answers

up vote 4 down vote accepted

You need both read and execute permissions on a script to be able to execute it. If you can't read the contents of the script, you aren't able to execute it either.

tony@matrix:~$ ./hello.world
hello world
tony@matrix:~$ ls -l hello.world
-rwxr-xr-x 1 tony tony 17 Jul 13 22:22 hello.world
tony@matrix:~$ chmod 100 hello.world
tony@matrix:~$ ls -l hello.world
---x------ 1 tony tony 17 Jul 13 22:22 hello.world
tony@matrix:~$ ./hello.world
bash: ./hello.world: Permission denied
share|improve this answer
Indeed, updated to reflect that it's true for scripts which considering the original question, is what I suspect is the case. – EightBitTony Jul 13 '11 at 22:49

If you let other users execute a program, then they can know everything the program is doing, whether the program file is readable or not. All they need to do is point a debugger (or debugger-like program such as strace). A binary executable can run if it's executable and not readable (a script can't, because the interpreter needs to be able to read the script), but this doesn't give you any security.

If you want others to be able to execute your program as a black box, without letting them see exactly what the program is doing, you need to give your script elevated privileges: make it setuid to your user. Only root can use debugging tools on setuid programs. Note that writing secure setuid programs isn't easy, and most languages aren't suitable; see Allow setuid on shell scripts for more explanations. If you're going to write a setuid program, I strongly recommend Perl, which has a mode (taint mode) that's explicitly intended to make secure setuid scripts possible.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.