Wednesday, 9 July 2025

Ubuntu set folder permission for inheritance (setfacl) && getfacl

 https://serverfault.com/questions/444867/linux-setfacl-set-all-current-future-files-directories-in-parent-directory-to


sudo setfacl -Rdm g:groupnamehere:rwx /base/path/members/
sudo setfacl -Rm g:groupnamehere:rwx /base/path/members/

R is recursive, which means everything under that directory will have the rule applied to it.
d is default, which means for all future items created under that directory, have these rules apply by default. m is needed to add/modify rules.

The first command, is for new items (hence the d), the second command, is for old/existing items under the folder. Hope this helps someone out as this stuff is a bit complicated and not very intuitive.


U can add others:


sudo setfacl -d -m g:your_group:rwx,o:rx /path/to/parentsudo setfacl -d -m g:your_group:rw,o:r /path/to/parent


for user just do:

setfacl -Rdm user:username:rwx /path/to/file



when u set permission ls -l you will see


drwxr-x---+ 4 root root 4096 Jul 14 11:29 test/


this user and group might be current user copied forlder to here or created here, but the permssion

for setfacl is already applied with + sign


see facl use

getfacl mydir/


cmd:

getfacl myfile.txt
This will output something like:
C++
# file: myfile.txt# owner: user1# group: group1user::rw-user:user2:rwxgroup::r--mask::rwxother::r--
Explanation:
  • # file: myfile.txt: Indicates the file being examined.
  • # owner: user1: Specifies the owner of the file.
  • # group: group1: Specifies the group associated with the file.
  • user::rw-: Defines the permissions for the file owner (read and write).
  • user:user2:rwx: Grants read, write, and execute permissions to user2.
  • group::r--: Specifies the permissions for the primary group (read only).
  • mask::rwx: Indicates the effective permissions for the group and named users.
  • other::r--: Defines the permissions for users who are not the owner or part of the primary group (read only). 

No comments:

Post a Comment