5

This is my user

$ id
uid=1000(pzk) gid=1000(pzk) groups=1000(pzk)

This is my directory structure

$ ls -tlrh
total 12K
d-w--w--w- 2 root root 4.0K Apr 13 10:53 write-for-everyone
dr--r--r-- 2 root root 4.0K Apr 13 10:53 read-for-everyone
d--x--x--x 2 root root 4.0K Apr 13 10:53 execute-for-everyone

From given permissions for write-for-everyone, I should be able to create a file inside write-for-everyone. But, I am NOT.

$ touch write-for-everyone/x
touch: cannot touch 'write-for-everyone/x': Permission denied

Please help me in figuring this out.

pzk
  • 117

2 Answers2

8

The w bit on a directory controls making changes to the list of filenames in the directory, so creating, renaming and removing files. But any of those operations also involves access the files themselves within the directory, and for that, the x permission is needed. A system call involved would be something like open("dir/file1", O_WRONLY | O_CREAT). The w does not give any access without the x bit.

On the other hand, reading the list of files in the directory works with only the r bit, as that only requires accessing the directory itself, not the files within. A system call involved would be something like open("dir", O_RDONLY).

In a sense, the x bit on directory dir controls access past the slash in a path like dir/somefile.

ilkkachu
  • 138,973
4

You cannot write inside this directory because you are not allowed to cross it.

Try adding execution rights on this directory, and you should now be able to create your file:

chmod 333 write-for-everyone/

The execution permissions on a folder means that you can enter it on Unix systems.
A bit more info here, and here.

Hope this helps !

ramius
  • 853