On GNU/Linux, you can traverse a directory if and only if you have execute permission on the whole path that you are going to use to access it. This rule applies a limitation to scenarios where for some reason you want to give execute access to a certain user on a subfolder but you do not want to enable the execute permission on the all the folders in the path.
In order to access the folder
theFolder in the path
/folderA/folderB/theFolder, if you are on the same level as
folderA (or higher) you need to have execute permission both on
folderA/folderB additionally to the permissions needed on
theFolder. On another scenario if you are located in the same level as
folderB (and you have execute rights to it) even if you do not have the execute rights to folder
folderA you would still be able to access
theFolder as your whole path (which is a relative path in this scenario) skips
folderA. This feature is due to the fact that in GNU/Linux that the path that you use to access a folder determines your access constraints. In cases where the user does not have execute access to the whole path, creating symbolic links for them will not help you give them access. The kernel will still go through the access rights of the whole path that the
symlink describes and it will act accordingly.
A hack-ish solution around this issue is to use
mount to remount a part of the file hierarchy somewhere else using the
bind parameter. For example: if we needed to give access to a user to the folder
theFolder that resides in
/folderA/folderB/theFolder without enabling execute rights on
/folderA/folderB we could execute the following command in a folder where that user already has execute access in (for example in the user’s home folder).
sudo mount --bind /folderA/folderB/theFolder finallyTheFolder;
- This solution circumvents security, be sure to think things through before implementing it
- This solution ‘escapes’ normal good practices so it could lead to software bugs on your behalf
- The bind will not persist after a reboot
- To make this change permanent, you will need to add a configuration line in /etc/fstab
- If the directory that you wish to bind contains mounted file systems, these file systems will not be transferred to the target. The mount points will appear as empty directories.