CodeGym /Courses /Docker SELF /Access Management with ACL (`setfacl`, `getfacl`)

Access Management with ACL (`setfacl`, `getfacl`)

Docker SELF
Level 5, Lesson 3
Available

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:

  1. Assigning individual permissions for files and directories to specific users and groups.
  2. Inheritance of permissions for new files inside a directory.
  3. More flexible setup compared to the traditional chmod approach.

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 user user2 (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:

  • Alice should have full access (read, write, execute).
  • Bob should only be able to read the files.
  • Eve should not see the directory at all.

We configure this using ACL:

  1. Give Alice full access:

    sudo setfacl -m u:alice:rwx /project
    
  2. Give Bob read-only access:

    sudo setfacl -m u:bob:r-- /project
    
  3. For 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

  1. ACL doesn't work even though you've set it up. Maybe the partition isn't mounted with the acl option. Use mount to check and remount it if needed.

  2. 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.

  3. 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.

1
Task
Docker SELF, level 5, lesson 3
Locked
Checking current ACL permissions
Checking current ACL permissions
1
Task
Docker SELF, level 5, lesson 3
Locked
Setting individual permissions for a user
Setting individual permissions for a user
1
Task
Docker SELF, level 5, lesson 3
Locked
Setting default permissions for a directory
Setting default permissions for a directory
1
Task
Docker SELF, level 5, lesson 3
Locked
Removing all ACL permissions
Removing all ACL permissions
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION