Skip to main content
Welcome to this comprehensive guide on advanced file system permissions in Linux. In this tutorial, we cover how to create, manage, and diagnose file permissions using standard permissions as well as Access Control Lists (ACLs) and additional file attributes. Imagine issuing the command:
This command lists files along with their permissions. In our example, files are owned by the user “adm” and belong to the “ftp” group. The permission sets are broken down as follows:
  • The first three bits (rw-) indicate that the owner (“adm”) can read and write.
  • The next three bits (rw-) allow members of the “ftp” group to also read and write.
  • The final three bits (r--) provide read-only access for other users.
Below is a sample output of the ls -l command:
Notice how the permissions allow the group and others different levels of access. For a user like Aaron Lockhart, who is not in the “ftp” group, only the read permission from the third set is applicable.
If we need to grant specific users additional access—such as providing Aaron Lockhart with write access to “file3” without altering his permissions for “file1” and “file2”—reassigning file ownership is not ideal, as it would remove write access from the regular owner (“adm”). Instead, Access Control Lists (ACLs) offer a more granular approach.

Creating a File with Standard Permissions

Let’s start by creating a new file called examplefile and setting its content to “This is the file content”. We then change the file’s ownership to user “adm” and group “ftp”:
Since the current user is neither “adm” nor a member of the “ftp” group, attempts to overwrite the file will result in a permission error. For example:
This command will yield an error such as “Permission denied”. However, reading the file with:
will correctly display its content:
Standard file permissions work well in most cases, but when finer control is necessary, ACLs can be used to grant specific permissions to additional users.

Granting Specific Permissions Using ACLs

To allow Aaron Lockhart to both read and modify examplefile, apply the following ACL command. If the file is not owned by the user, prepend the command with sudo:
With this ACL in place, Aaron can now overwrite the file:
After modifying the file, the presence of ACLs is indicated by a plus sign (+) in the permission listing:
To inspect detailed ACL settings, use the getfacl command:
Example output:
The mask setting defines the maximum permissions available to users and groups affected by ACLs. This means that even if an ACL grants extended permissions, the effective permissions will be restricted by the mask. To enforce read-only access despite broader ACL entries, set the mask to r--:

Modifying ACLs for Groups and Removing ACL Entries

ACLs can also apply to groups. To grant the “wheel” group read and write access, execute:
If you need to restrict a user’s permissions completely (for example, to deny Aaron Lockhart any access), set his permissions to none:
Should you wish to remove a specific ACL entry entirely, use the --remove option:
Similarly, to remove a group ACL entry:

Applying ACLs Recursively

In cases where you need to update ACLs for an entire directory and its contents, utilize the recursive flag (--recursive or -R). For example, to grant Aaron full permissions on all files within directory dir1:
To remove an ACL entry recursively from a directory:

Managing File and Directory Attributes

Beyond ACLs, Linux file systems support attributes that serve as on/off switches to control file behavior. Two frequently used attributes are append-only and immutable.

Append-Only Attribute

First, create a new file with initial content:
To enable the append-only attribute, use chattr with the +a flag. With this attribute active, you can append data but cannot overwrite the file’s existing contents:
Verifying the content:
Attempting to overwrite the file:
Appending new content is allowed:
To remove the append-only attribute, use:

Immutable Attribute

When a file is marked as immutable (indicated by the letter i), it becomes completely unmodifiable—even root cannot delete or alter the file. To set the immutable attribute:
Any attempt to remove the file, even with elevated privileges, will result in an error:
To view file attributes, run:
Expected output:
Remove the immutable attribute with:
For further information on available attributes beyond append-only and immutable, refer to the manual page for chattr. Note that some attributes may have no effect, depending on your file system type. For instance, the c attribute for compression does not work on file systems such as ext4 that do not support on-the-fly compression.
The image shows a terminal window displaying a manual page for the chattr command, detailing file attributes like 'C', 'd', and 'D'.
Always verify your file system’s support for specific attributes to avoid unexpected behavior. Explore man chattr for a detailed list.

Conclusion

This tutorial provided an in-depth look at managing advanced file system permissions and attributes in Linux. You learned how to work with standard file permissions, leverage ACLs to grant specific user and group privileges, and handle additional file attributes like append-only and immutable. Continue practicing these commands in your lab exercises to enhance your proficiency in Linux system management. For more detailed information, consider exploring additional resources: Happy learning!

Watch Video