Using xattrs or Extended Attributes on Linux

Using xattrs or Extended Attributes on Linux

Extended attributes, xattrs for short, are an extensible mechanism to store metadata along files. In other words, they describe some additional properties of the file. Normally this information is limited, like ownership and dates. With xattrs more information can be stored about the file.

Support for xattrs

Not all file systems have support for xattrs, but nowadays the most common ones support it (EXT4, Btrfs, ReiserFS, JFS and ZFS). To determine if your file system has xattr support enabled, check the options file of the related device:

# cat /proc/fs/ext4/sda1/options | grep xattr

One way to set an attribute for a file, is by adding an access control list (ACL) with the setfacl command. For example we want to allow the web server daemon to read data from /data/storage.

# setfacl -m u:www-data:r /data/storage

Running the command won’t give any output. So let’s check if something has changed:

# ls -l
total 4
drwxr-xr-x+ 2 root root 4096 Nov 18 16:00 storage

The plus sign in ls reveals there is something different than other files. Of course this is because of adding the extended attribute.

Although we could use the getfacl command to determine the permissions, we can actually use the getfattr command to see what kind of attribute is added.

# getfattr /data/storage


getfattr: Removing leading ‘/’ from absolute path names
# file: data/storage

Now we now for sure it is an ACL stored in the extended attributes of this particular file (or actually directory).

If we want to see detailed information, we can use the xattr tool for that.

Screenshot listing the extended attributes of a file

Using xattr to list extended attributes of a file

Other attributes


The security.capability files stores Linux capabilities for the related file. Applies to binaries which are provided one or more capabilities via this file.


For the Integrity Measurement Architecture (IMA), the file security.ima stores a hash or digital signature.


Similar to security.ima, the Extended Verification Module (EVM) stores a hash/HMAC or digital signature in this file. The different with IMA is that it protects the metadata of the file, not the contents.

Related tools


Installation: apt-get install acl


Installation: apt-get install attr


Installation: apt-get install python-xattr


More resources

Two useful links suggested by our readers, are:

One more thing...

Keep learning

So you are interested in Linux security? Join the Linux Security Expert training program, a practical and lab-based training ground. For those who want to become (or stay) a Linux security expert.

See training package

Lynis Enterprise screenshot to help with system hardeningSecurity scanning with Lynis and Lynis Enterprise

Run automated security scans and increase your defenses. Lynis is an open source security tool to perform in-depth audits. It helps with system hardening, vulnerability discovery, and compliance.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.