I just learned something that shocked me, because I did not have a clue it was a fact.
If I have a directory with the following permissions:
user@host:~$ ls -la testdir
total 8
drwxrwxrwx 2 user user 4096 Mar 3 20:36 .
drwx------ 34 user user 4096 Mar 3 20:36 ..
-rw-r--r-- 1 user user 0 Mar 3 20:36 testfile 1
-rw-r--r-- 1 user user 0 Mar 3 20:36 testfile 2
Even though the files testfile 1
and testfile 2
have write permissions only for the owner everyone can write on them.
Until now, I thought that the directories' permissions only affected the directory itself.
So now for my question - what good are file permissions on files, if everything seems to be set by the directories' permissions that the files reside in?
==== EDIT 1 ====
On the other hand look at these permissions:
[user@geruetzel2 default]$ ls -la
total 24
drwxr-xr-x. 2 root root 41 Dec 19 23:07 .
drwxr-xr-x. 96 root root 8192 Mar 3 20:28 ..
-rw-r--r--. 1 root root 354 Dec 19 23:07 grub
-rw-r--r--. 1 root root 1756 Nov 30 19:57 nss
-rw-------. 1 root root 119 Mar 6 2015 useradd
If I do a cat useradd
as non-root here, I get a permission denied error. Why is that? The direcory has read permissions for "other" so it should be readable? There seems to be a difference between the two examples I gave but I don't see the reason for the different behavior.