0

Can someone please explain how is user "saad" able to delete the files/folders created in /project directory by root user. Saad user is the owner of folder /project. The owner and group owner of all these files/folders inside the /project is root as we can see. And for the other users either it is no permission or it is read only or read-execute for some. No files/folders have user saad as the owner.

Once the user saad cd inside the /project folder, the permissions applied to user saad will be from other user permissions ? Based on what privileges, user saad is able to delete all these files/folders.

[saad@localhost ~]$ ls -ld /project/
drwxrwxrwx. 8 saad devteam 94 Jan 16 06:55 /project/
[saad@localhost ~]$ ll /project/
drwxr-xr-x. 2 root root   6 Jan 10 16:41 dir1
drwxr-xr--. 2 root root   6 Jan 15 17:54 dir2
drwxr-xr--. 2 root root   6 Jan 10 16:41 dir3
drwxr-xr-x. 2 root root   6 Jan  6 17:23 dir4
drwxr-xr-x. 2 root root   6 Jan  6 17:23 dir5
drwxr-x---. 2 root root   6 Jan 16 06:54 dir7
-rw-r-----. 1 root root 143 Jan 10 17:19 file.txt
  • 1
    Because the folder project is owned by saad and this one has write(w) permissions. When you apply rm to a file the permissions of the parent directory allow/deny the deletion of this one. – Edgar Magallon Jan 16 '23 at 07:17
  • @EdgarMagallon I thought since the user can't read them , can't cd in to them so also will not be able to delete them. But it appears the delete permission comes from the parent directory not from other users permissions. – Saad Azhar Jan 16 '23 at 07:22
  • The way permissions work wrt. file deletion is likely discussed in multiple answers before, see e.g. https://unix.stackexchange.com/q/526283/170373 But permissions on dir/ aren't enough to delete files contained in dir/subdir/, and the latter directory needs to be empty to be removed. – ilkkachu Jan 16 '23 at 07:29
  • @ilkkachu right. I just tried it. I was able to delete all the directories as long as they were empty. But as soon as I created a file inside of the subdir, I wasn't able to delete that subdir anymore. In order to delete the subdir that contains files inside of it, the user must have write and execute permissions on it ? – Saad Azhar Jan 16 '23 at 07:42
  • @SaadAzhar, yes, you need write+"execute" on dir/subdir/ to delete dir/subdir/file to make dir/subdir empty. And the same recursively. (Better think of the x permission as "access" on directories since really it has nothing to do with execution) – ilkkachu Jan 16 '23 at 07:51
  • @ilkkachu this is very much clear. Now I'm trying to delete the parent /project directory. I'm the owner and I have 7 rights as well. But still when I try to delete, it says : Permission denied. Why is that? – Saad Azhar Jan 16 '23 at 08:56
  • @SaadAzhar, well, do you have write access to the directory containing that directory? – ilkkachu Jan 16 '23 at 09:02
  • @ilkkachu this is / directory and I don't have w access to the / directory which contains /project directory. I have done some testing adding/deleting files and rights. Will this statement be true that If i'm owner with full rights to a file/folder and still unable to delete it, that means someone else created that file/folder and made me owner later on. And i cannot delete it because i don't have write permission to its parent directory? – Saad Azhar Jan 16 '23 at 09:26

0 Answers0