Linux directory permission inheritance
Asked Answered
T

2

8

Can someone explain to me how directory permissions are inherited in Linux (Ubuntu, specifically)?

For example, what if I have the following directory structure:

folder_A
    folder_B

Do folder_A's permissions always override folder_B's? Is there any difference if folder_A's permissions are more restrictive than folder_B's, or vice-versa?

My guess would be that if folder_B had more restrictive permissions, it would override folder_A's, but if folder_A had more restrictive permissions, then it would override its children.

Tolkan answered 19/7, 2013 at 12:43 Comment(1)
Perhaps this question should go to the Unix & Linux SE.Hartzel
Y
9

The way permissions affect paths is explained in the path_resolution man page: http://linux.die.net/man/2/path_resolution

The only permission on folder A that matters is the search (execute) permission: if you don't have it you can't descend to folder B. Other than that there is no relation between permissions of A and B, for example if A is read-only and B is not, or even if you don't even have read permission to A, you still can create and delete files in B.

Yukoyukon answered 19/7, 2013 at 12:56 Comment(3)
What if folder_B has a PHP file that needs to be executed, but folder_A has restrictions on that? Would I need to set permissions all the way up folder_B's lineage (if, say, folder_B was 4 or 5 levels deep)?Tolkan
Yes you need to have permission to access all the way downRedneck
A folder cannot restrict the execution permission of a file. The only thing it can do is block all access altogether - I recommend reading the path resolution page to get the full detail.Yukoyukon
O
5

I like to think of folders as Gatekeepers. Each folder's permissions allow to you view that folder and any below it. Once you are past one Gatekeeper, you are past it, and the permissions involved in that folder no longer matter. More specifically, the execute permission on folders is actually the ability to enter(list the files within) it. Each file has the permission on whether it is write/read/executable.

So, as long as you have the permissions to view/read the files inside one folder, you can move into a child folder and do whatever that folder gives you permission to do.

Otherwise answered 19/7, 2013 at 18:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.