- 1View File Permissions in Linux
- 2Change File Permissions with chmod in Linux
- 3How to Use Numeric Mode with chmod in Linux
- 4chmod Symbolic Mode in Linux
- 5How to Change File Ownership in Linux
- 6How to Change Group Ownership Using chgrp in Linux
- 7Understanding Linux File Permission Symbols (r, w, x)
- 8Linux File Permissions - User, Group, Others
- 9Understanding Special Permissions in Linux: SUID, SGID, and Sticky Bit
- 10How to Use ACLs in Linux - Set File Permissions
- 11Set ACL Permissions in Linux with setfacl
- 12How to View ACLs using getfacl in Linux
- 13Find Files by Permissions in Linux
How to Set ACL Permissions Using setfacl
How to Set ACL Permissions Using setfacl
Welcome to this beginner-friendly Linux tutorial! Today, we're going to learn how to use setfacl
to apply Access Control Lists (ACLs) on files and directories.
ACLs allow you to give specific users or groups custom permissions on top of the traditional owner-group-others model. Super useful when you want to allow more than one user access to a file or directory — with different permission levels!
Step 1: Create a Directory and File
Let’s begin by creating a sample directory and a file.
mkdir acl_demo
cd acl_demo
touch report.txt
Step 2: View Default Permissions
ls -l report.txt
-rw-r--r-- 1 user user 0 Jul 2 10:00 report.txt
Right now, only the file owner (you) can write to this file. Others can only read it.
Step 3: Grant Write Permission to Another User Using setfacl
Suppose we want to give write permission to another user, say alice
.
setfacl -m u:alice:w report.txt
Here’s what this means:
-m
means modify ACLu:alice:w
means give user 'alice' write access
Step 4: Check the Updated ACL
getfacl report.txt
# file: report.txt
# owner: user
# group: user
user::rw-
user:alice:-w-
group::r--
mask::rw-
other::r--
Now you can see that alice
has write permission!
Step 5: Give Multiple Permissions (Read + Write)
setfacl -m u:alice:rw report.txt
Check again:
getfacl report.txt
user:alice:rw-
Step 6: Set Default ACLs on a Directory
If you want every new file in a directory to inherit ACL permissions automatically:
setfacl -d -m u:alice:rw acl_demo
The -d
flag sets default ACLs.
Step 7: Remove ACL for a User
setfacl -x u:alice report.txt
This removes all ACL permissions for user alice
from report.txt
.
Step 8: Remove All ACLs
setfacl -b report.txt
This command removes all ACL entries and resets the file to standard permissions.
Bonus: Check if ACLs are Enabled
To check if your filesystem supports ACLs:
tune2fs -l /dev/sdX | grep "Default mount options"
Replace /dev/sdX
with your actual disk device.
That's It!
Now you know how to use setfacl
to grant specific permissions to different users in Linux.
This is especially useful in shared environments and multi-user systems.
Practice with sample files and explore combining ACLs with traditional permissions for powerful control.
Next Topic ⮕How to View ACLs using getfacl in Linux
Comments
Loading comments...