1. Introduction to ACL
Imagine you're hosting a party (or managing a system). You want the guests to be able to visit certain rooms, but others—only with your permission. Basic Linux permissions rwx let you control access for just three categories: owner (user), group (group), and everyone else (others). But what if you need to grant access to a specific friend for a room? The gatekeeper for the standard permissions model would tell you, "Hey, that's not gonna work." That's where ACL comes in to save the day.
ACL (Access Control Lists) solve the limitations of the classic three-level permission system by allowing you to set access rights for specific users and groups.
Main features of ACL:
- Assigning individual permissions for files and directories to specific users and groups.
- Inheritance of permissions for new files inside a directory.
- More flexible setup compared to the traditional
chmodapproach.
2. How to check if ACL is enabled?
Before diving into ACL management, let’s find out if your system supports them. You can check this with the command:
mount | grep acl
If the file system is mounted with the acl option, you're good to go! Otherwise, you’ll need to remount the partition with the acl option added:
sudo mount -o remount,acl /your/mount/point
Alright, now you’re all set. It’s time to dive into practice.
3. Main Commands for Working with ACL
| Command | Description |
|---|---|
getfacl |
Get the current list of ACL for a file or directory. |
setfacl |
Set or modify ACL for a file or directory. |
setfacl -m |
Modify current access permissions. |
setfacl -x |
Remove specific access permissions. |
setfacl -b |
Remove all ACL entries for a file or directory. |
setfacl -d |
Set default permissions for a directory that are inherited by files. |
Now let’s break down each of these commands with examples!
Getting Current ACL getfacl
Let’s say we’ve got a file called example.txt. We wanna check the current access permissions using ACL. One single command is enough:
getfacl example.txt
Output might look something like this:
# file: example.txt
# owner: user1
# group: group1
user::rw-
group::r--
other::---
This list shows standard permissions: the owner user1 can read and write, the group group1 can only read, and others can’t access it at all.
Setting Individual Access Permissions (setfacl)
Now imagine that user user2 needs write access to the file example.txt. You can do it like this:
sudo setfacl -m u:user2:rw example.txt
The command means:
-m: modify permissions.u:user2:rw: add or change permissions for useruser2(read-write).
Let’s check the result:
getfacl example.txt
Now the output looks like this:
# file: example.txt
# owner: user1
# group: group1
user::rw-
user:user2:rw # Added rule!
group::r--
other::---
Removing Individual Access Permissions setfacl -x
If you decide that user user2 no longer needs write access, you can remove the permissions:
sudo setfacl -x u:user2 example.txt
Let’s check:
getfacl example.txt
No extra rules for user2 anymore!
Setting Permissions for Groups
With ACL, you can set permissions not just for individual users but for entire groups. For example, to give the group devteam read and write access, run:
sudo setfacl -m g:devteam:rw example.txt
Setting Default Permissions setfacl -d
Sometimes you need automatic permissions for all new files and directories inside a specific directory. For instance, if you want all files in the directory project_dir to have write access for user developer, do this:
sudo setfacl -d -m u:developer:rw project_dir
You can check the permissions like this:
getfacl project_dir
Now all new files and subdirectories in project_dir will follow this default rule.
Removing All ACL setfacl -b
If you wanna completely clear all ACL for a file:
sudo setfacl -b example.txt
The file will now revert to the standard permission model user:group:others.
4. Practical Use of ACL
Scenario: Collaborative Work on a Project
Let's say you have a project stored in the directory /project. Three people are working on it:
Aliceshould have full access (read, write, execute).Bobshould only be able to read the files.Eveshould not see the directory at all.
We configure this using ACL:
Give
Alicefull access:sudo setfacl -m u:alice:rwx /projectGive
Bobread-only access:sudo setfacl -m u:bob:r-- /projectFor
Eve, we do nothing — she will not have access by default.
Let's check the current ACL list:
getfacl /project
Output:
# file: /project
# owner: root
# group: root
user::rwx
user:alice:rwx
user:bob:r--
group::---
other::---
Now Alice can work without restrictions, Bob can only view the files, and Eve is left out.
5. Potential Errors and Their Solutions
ACL doesn't work even though you've set it up. Maybe the partition isn't mounted with the
acloption. Usemountto check and remount it if needed.Conflict between standard permissions and ACL. ACL always takes precedence over standard permissions. For example, even if "others" have read access denied, ACL can give access to a specific user.
You forget about inherited ACLs. If you've set
-d(default) permissions, check if these rules are inherited by new files.
Why is this important?
Managing permissions via ACL lets you flexibly configure access for different users and groups. This is especially useful on work servers where access rights need to be distributed with roles in mind. For example, in companies, ACL is used to restrict access only to those who "are in the know" — one of the keys to security.
Additionally, you can check out the official ACL guide to understand their capabilities even better.
GO TO FULL VERSION