0

When I create a directory as a root user with permission 777, then I can delete it when I am logged in as default user but when I logged in as a or b user, I can't able to delete it. It's showing permission denied.

My question is, why can my default user delete that folder created by root and why other users can't, tough all are having 777 permission.

6
  • Do those users have write permission to the parent directory of the one with 777 permissions? Commented Nov 25, 2019 at 10:02
  • 1
    The ability to delete a file or directory mainly depends on the permissions and ownership of the directory where the directory or file is located. If a user owns a directory dir, and has write permissions in it, they would be able to delete files in it that belongs to other users. Commented Nov 25, 2019 at 10:04
  • no, I don't know. But root gave 777 permission. so anyone can delete it right? then why only default user? Commented Nov 25, 2019 at 10:05
  • #Kusalananda But root created that directory then no one can delete it other than root, then why my default user can delete it. Commented Nov 25, 2019 at 10:08
  • @SubirMakur If that user owns the directory in which the subdirectory owned by root was created, the user can delete the root-owned subdirectory. It has nothing to do with the ownership nor permissions on the subdirectory. Commented Nov 25, 2019 at 10:10

1 Answer 1

1

If a user has write and execute permissions on a directory, they can delete any file or directory therein, regardless of the ownerships of those. It is so because the deletion of a file or subdirectory from a directory is a modification to the directory, not to the thing being deleted.

Example: I create a directory owned by root in a directory that I own, then delete it.

$ sudo mkdir directory
$ ls -l
total 4
drwxr-xr-x  2 root  wheel  512 Nov 25 11:11 directory
$ rmdir directory
$ ls -l

(no output)

Now, if the subdirectory contains files, then the permissions on that directory becomes more interesting:

$ sudo mkdir directory
$ sudo touch directory/file
$ rm -rf directory
rm: directory/file: Permission denied
rm: directory: Directory not empty

Here, I can't delete the subdirectory because I have no permissions to delete the file that is inside it.

But you say that the permissions are set to 777, which means anyone could delete the files inside it:

$ sudo chmod 777 directory
$ rm -rf directory

(no error)

Another user on my system would still not be able to do this, because they have no write permissions in the directory where I'm working, although they could still delete the contents of the root-owned subdirectory, if that directory was accessible to them (the users would need execute permissions on the directory and all parent directories).

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.