fscrypt
fscrypt is a high-level tool for the management of Linux native filesystem
encryption.
fscrypt manages metadata, key generation, key wrapping, PAM integration, and
provides a uniform interface for creating and modifying encrypted directories.
For a small low-level tool that directly sets policies, see
fscryptctl.
To use fscrypt, you must have a filesystem that supports the Linux native
filesystem encryption API (which is also sometimes called "fscrypt"; this
documentation calls it "Linux native filesystem encryption" to avoid confusion).
Only certain filesystems, such as ext4 and
f2fs, support this API. For a full list
of supported filesystems and how to enable encryption support on each one, see
Runtime dependencies.
For the release notes, see the NEWS file.
Table of contents
Alternatives to consider
Operating-system level storage encryption solutions work at either the
filesystem or block device level. Linux native filesystem
encryption
(the solution configured by fscrypt) is filesystem-level; it encrypts
individual directories. Only file contents and filenames are encrypted;
non-filename metadata, such as timestamps, the sizes and number of files, and
extended attributes, is not encrypted. Users choose which directories will
be encrypted, and with what keys.
Before using fscrypt, you should consider other solutions:
dm-crypt/LUKS is block device
level encryption: it encrypts an entire block device (and hence an entire
filesystem) with one key. Unlocking this key will unlock the entire block
device. dm-crypt/LUKS is usually configured using
cryptsetup.
systemd-homed supports encrypting home
directories using the same Linux native filesystem encryption API that
fscrypt uses. Note that while the systemd-homed documentation refers to
this as fscrypt support, it does not use the fscrypt tool; directories set
up using systemd-homed cannot be managed by fscrypt and vice versa.
systemd-homed has better integration with systemd than fscrypt does.
However, systemd-homed (as of systemd v255) uses the
"V1" Linux kernel encryption API,
while fscrypt prefers the "V2" API. The older API causes
known issues, and
migrating systemd-homed to the "V2" API is tracked
in this systemd issue.
Issues with systemd-homed should be reported to the systemd developers.
eCryptfs is an alternative
filesystem-level encryption solution. It is a stacked filesystem, which means
it sits on top of a real filesystem, rather than being directly integrated
into the real filesystem. Stacked filesystems have a couple advantages (such
as working on almost any real filesystem), but also some significant
disadvantages. eCryptfs is usually configured using
ecryptfs-utils.
Some Linux filesystems support encryption natively, but not in a way that is
compatible with the common API that fscrypt uses. Examples of this are
Bcachefs and ZFS. (Note: ZFS is not part of the upstream kernel.) Bcachefs
encryption is similar to dm-crypt in that it encrypts the full filesystem with
one key. ZFS encryption operates on a per-dataset basis. If you are using
one of these filesystems, refer to the documentation for that filesystem.
Which solution to use? Here are our recommendations:
eCryptfs shouldn't be used, if at all possible. eCryptfs's use of filesystem
stacking causes a number of issues, and eCryptfs is no longer actively
maintained. The original author of eCryptfs recommends using Linux native
filesystem encryption instead. The largest users of eCryptfs (Ubuntu and
Chrome OS) have switched to dm-crypt or Linux native filesystem encryption.
If you need fine-grained control of encryption within a filesystem and you are
using a filesystem that supports fscrypt, then use fscrypt, or fscrypt
together with dm-crypt/LUKS. If you don't need this, then use dm-crypt/LUKS.
To understand this recommendation: consider that the main advantage of
fscrypt is to allow different files on the same filesystem to be encrypted
by different keys, and thus be unlockable, lockable, and securely deletable
independently from each other. Therefore, fscrypt is useful in cases such
as:
Multi-user systems, since each user's files can be encrypted with their
own key that is unlocked by their own passphrase.
Single-user systems where it's not possible for all files to have the
strongest level of protection. For example, it might be necessary for the
system to boot up without user interaction. Any files that are needed to
do so can only be encrypted by a hardware-protected (e.g. TPM-bound) key
at best. If the user's personal files are located on the same filesystem,
then with dm-crypt/LUKS the user's personal files would be limited to this
weak level of protection. With fscrypt, the user's personal files could
be fully protected using the user's passphrase.
fscrypt isn't very useful in the following cases:
Single-user systems where the user is willing to enter a strong passphrase
at boot time to unlock the entire filesystem. In this case, the main
advantage of fscrypt would go unused, so dm-crypt/LUKS would be better
as it would provide better security (due to ensuring that all files and
all filesystem metadata are encrypted).
Any case where it is feasible to create a separate filesystem for every
encryption key you want to use.
Note: dm-crypt/LUKS and fscrypt aren't mutually exclusive; they can be used
together when the performance hit of double encryption is tolerable. It only
makes sense to do this when the keys for each encryption layer are protected
in different ways, such that each layer serves a different purpose. A
reasonable set-up would be to encrypt the whole filesystem with dm-crypt/LUKS
using a TPM-bound key that is automatically unlocked at boot time, and also
encrypt users' home directories with fscrypt using their login passphrases.
Threat model
Like other storage encryption solutions (including dm-crypt/LUKS and eCryptfs),
Linux native filesystem encryption is primarily intended to protect the
confidentiality of data from a single point-in-time permanent offline compromise
of the disk. For a detailed description of the threat model, see the kernel
documentation.
It's worth emphasizing that none of these encryption solutions protect unlocked
encrypted files from other users on the same system (that's the job of OS-level
access control, such as UNIX file permissions), or from the cloud provider you
may be running a virtual machine on. By themselves, they also do not protect
from "evil maid" attacks, i.e. non-permanent offline compromises of the disk.
Features
fscrypt is intended to improve upon the work in
e4crypt by providing a
more managed environment and handling more functionality in the background.
fscrypt has a design document specifying its full
architecture. See also the kernel documentation for Linux native filesystem
encryption.
Briefly, fscrypt deals with protectors and policies. Protectors represent some
secret or information used to protect the confidentiality of your data. The
three currently supported protector types are:
Your login passphrase, through PAM.
The included PAM module (pam_fscrypt.so) can automatically unlock
directories protected by your login passphrase when you log in, and lock them
when you log out. IMPORTANT: before using a login protector, follow
Setting up for login protectors.
A custom passphrase. This passphrase is hashed with
Argon2id, by default calibrated to
use all CPUs and take about 1 second.
A raw key file. See Using a raw key protector.
These protectors are mutable, so the information can change without needing to
update any of your encrypted directories.
Policies represent the actual key passed to the kernel. This "policy key" is
immutable and policies are (usually) applied to a single directory. Protectors
then protect policies, so that having one of the protectors for a policy is
enough to get the policy key and access the data. Which protectors protect a
policy can also be changed. This allows a user to change how a directory is
protected without needing to reencrypt the directory's contents.
Concretely, fscrypt contains the following functionality:
fscrypt setup - Creates /etc/fscrypt.conf and the /.fscrypt directory
- This is the only functionality which always requires root privileges
fscrypt setup MOUNTPOINT - Gets a filesystem ready for use with fscrypt
fscrypt encrypt DIRECTORY - Encrypts an empty directory
fscrypt unlock DIRECTORY