If a file has permissions -rwx-wx-wx can it be read by other and group users, or can it only executed and written? Is there some way to read an executable file by executing it?

  • No standard way that I can tell. – Tim Jan 19 '12 at 21:10

A file with -rwx-wx-wx permissions has read/write/execute permissions for the owner, and write/execute (but not read) permissions for everyone else.

If it's a script (usually a text file with a #! on the first line), then it can't be executed by others, because executing a script really executes the interpreter, which must be able to read the script. (The interpreter must be a binary, not another script.) (Actually, that's not true for all systems; Ubuntu, with a 3.2.0 Linux kernel, allows the interpreter itself to be an interpreted script. There seems to be a limit of about 4 levels. That's not likely to be relevant to this question.)

If it's a binary executable, it can be executed directly, but its contents can't be read. This means, for example, that someone other than the owner can run it as a command, but can't grab a copy of the executable.

Of course execution requires reading, but it's read by the kernel, not by the user. You might be able to get some information about the contents of the executable by examining the memory of the process as it's running, but I doubt that you could reconstruct the binary executable file. And if the executable is setuid, you can't examine the memory of the process (unless you have access to the account under which it's executing).

Incidentally, -rwx-wx-wx is a very odd set of permissions; it protects the file from being read by anyone other than the owner, but allows anyone to modify it. I can't think of a case where that would make sense.

  • Just an abstract random question : Would profiling/debugging tools work on execs with only executable permissions ? – Sairam Jan 23 '12 at 19:46
  • @Sairam: Experiment says no: chmod 111 hello ; gdb ./hello says ./hello: Permission denied.; r says No executable file specified. – Keith Thompson Jan 23 '12 at 19:53
  • For a non-executable, something like -rw--w--w- can be useful for something like a log file where you want people to be able to write info to the log without being able to read it. Of course, they could just empty the file, but that's a separate issue. – Dave Jan 25 '12 at 21:33

With those permissions, only the owner of the file can execute it.

Other users can write to it, but not execute it (as execution in this case implies being able to read it) but they can write to it as a sort of black box:

user1:~$ cd /tmp
user1:/tmp$ echo "hostname" > testfile.sh
user1:/tmp$ chmod +x testfile.sh 
user1:/tmp$ ./testfile.sh  

user1:/tmp$ chmod 733 testfile.sh 
user1:/tmp$ ls -l testfile.sh 
-rwx-wx-wx 1 user1 user1 9 Jan 19 21:09 testfile.sh

user1:/tmp$ sudo su - user2
user2:~$ cd /tmp
user2:/tmp$ ./testfile.sh  
./testfile.sh: Permission denied
user2:/tmp$ cat testfile.sh 
cat: testfile.sh: Permission denied

user2:/tmp$ echo 'echo hello' >> testfile.sh 
user2:/tmp$ ./testfile.sh  
./testfile.sh: Permission denied

user2:/tmp$ logout

user1:/tmp$ ./testfile.sh
  • 4
    A shell script requires READ as well as EXECUTE access to run. However, a compiled binary does NOT. Thus a compiled binary with the permissions above could be executed by anybody! – mdpc Jan 19 '12 at 21:24
  • 1
    I suppose this brings up the question on what the OP is trying to accomplish, i.e., why would the compiled binary be writable? The set of permissions (733) actually took a moment for me to figure out, since it's so non-standard. – cjc Jan 19 '12 at 21:28

The simple answer is no: only exec syscall may read a file without requiring read access (although mandating execute access). An open with O_RDONLY or O_RDWR shall fail.


Of course any file can be read by the root user.

Also, the system loader, memory management, swapper, etc....will read a file with 'x' permission, otherwise it could not be executed.

Possible holes in disclosing executable contents could be the /proc file for the process, core files, or by using a debugger.

  • this is only true if a chmod|chown has been performed – warren Jan 23 '12 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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