Skip to main content

Linux Home Encryption Policy

Overview

The Linux Home Encryption Policy (LINUX_HOME_ENCRYPTION_POLICY) allows administrators to manage home directory encryption for specific Linux users as an alternative to full disk encryption. In many Linux environments, enabling full disk encryption requires reinstalling the operating system — home directory encryption provides a targeted, non-disruptive alternative that protects user data at rest.

This policy is available for both BYOD and company-owned devices. The device must not be TPM-enabled.


Supported Platforms

Requirement

Details

Operating System

Linux

File System

ext4 only

Encryption Tool

fscrypt (preferred). Legacy ecryptfs is not used.

Device Ownership

Company-owned and BYOD (Non TPM)


How It Works

The Linux Home Encryption Policy uses fscrypt to encrypt the home directories of specified users. The encryption process follows these rules:

  1. Encryption only runs while the target user is logged out. If a user in the policy's user list is currently logged in, their home directory will not be encrypted during that session. This prevents file corruption from encrypting an active home directory.

  2. Encryption is applied on the next login cycle. When another user logs in and the target user is logged out, the agent encrypts the logged-out user's home directory.

  3. All users are encrypted after a full login cycle. By cycling through logins (e.g., logging in as each user in turn), all specified users' home directories will be encrypted.

Encryption Details

Once encrypted, a user's home directory will report the following fscrypt configuration:

  • Contents encryption: AES-256-XTS

  • Filenames encryption: AES-256-CTS

  • Padding: 32

  • Policy version: 2

Device Compliance Reporting

When this policy is active, the device will report encryption status back to the Swif console:

Status

Meaning

Encrypted

The user's home directory is encrypted via fscrypt

Unencrypted

The user's home directory is not encrypted

This status is visible in the device details under MDM Device Info > Encryption.


Policy Configuration

1. Apply to All Users (allUsers)

Property

Value

Type

Boolean

Default

false

Required

No

Platform

Linux

Specifies whether to manage home encryption for all users on the device or only for specific users defined in the User List.

  • true — Home encryption will be managed for all users on the device.

  • false — Home encryption will be managed only for users specified in the userList field.

Note: When allUsers is set to true, the userList field is ignored. A dedicated boolean field is used (rather than placing "all" in the user list) to avoid ambiguity in cases where a Linux username is literally "all."


2. User List (userList)

Property

Value

Type

Array of Strings

Default

None

Required

No

Platform

Linux

Specifies the Linux usernames whose home directory encryption should be managed by this policy. This field is only used when allUsers is set to false.

Example value:

["john", "jane", "deploy-user"]

Tip: Use the exact Linux username (login name) as it appears in /etc/passwd.

Quick Reference

Field

Display Name

Type

Default

allUsers

Apply to All Users

Boolean

false

userList

User List

Array of Strings

—


Verifying Encryption Status

After the policy has been applied, you can verify whether a user's home directory is encrypted by running:

sudo fscrypt status /home/<username>

If encrypted, the output will show:

"/home/userB" is encrypted with fscrypt.

Policy: <policyId>
Options: padding:32 contents:AES_256_XTS filenames:AES_256_CTS policy_version:2
Unlocked: Yes

Protected with 1 protector:
...

If not encrypted, the output will indicate that no fscrypt policy is applied to the directory.


Troubleshooting: User Is Returned to the Login Screen

A user may enter the correct password but be returned to the graphical login screen. This can occur when the user’s home directory remains encrypted and the automatic fscrypt unlock operation does not complete during startup.

The password itself may be valid. The graphical desktop cannot start because it cannot read files such as ~/.config while the encrypted home directory is locked.

In rare cases, this can be caused by the startup order of the services involved in unlocking the home directory.

Important: Do not repeatedly use the graphical login while troubleshooting. Use a text console and preserve the existing encrypted directory and key files.

1. Open a Text Console

From the graphical login screen:

  1. Press Ctrl + Alt + F3.

  2. Sign in using a different sudo-enabled administrator account.

  3. Remain in the text console until troubleshooting is complete.

Using a different administrator prevents the target user from retaining an active session. If no other administrator account is available, contact Swif Support before continuing.

2. Check the Home Directory’s Encryption Status

Replace <username> with the affected Linux username:

sudo fscrypt status /home/<username>

A locked directory reports:

"/home/<username>" is encrypted with fscrypt. Unlocked: No

Encrypted filenames may appear as long, unreadable strings when the key is not loaded. This does not mean the files are empty or deleted.

3. Confirm That the User Has No Active Session

Run:

loginctl list-sessions

If the affected user has an active graphical session, terminate it from the alternate administrator account:

sudo loginctl terminate-user <username> 
loginctl list-sessions

There should be no remaining session for the affected user before attempting to unlock or decrypt the home directory.

4. Check for the Swif-Managed Key

Swif-managed encryption normally creates files under:

/var/lib/swifteam/fscrypt/

Check for the affected user’s key without displaying its contents:

sudo ls -la /var/lib/swifteam/fscrypt/ 
sudo test -f /var/lib/swifteam/fscrypt/<username>.key \
&& echo "Key exists" \
|| echo "Key is missing"

The expected key path is:

/var/lib/swifteam/fscrypt/<username>.key

Security warning: The key file is sensitive encryption material. Do not open it in an editor, print its contents, include it in logs, or send it through email or chat.

5. Unlock the Home Directory When the Key Exists

If the key exists, use it directly:

sudo fscrypt unlock /home/<username> \   
--key=/var/lib/swifteam/fscrypt/<username>.key

Then verify the result:

sudo fscrypt status /home/<username> 
sudo ls -la /home/<username> | head

The status should report:

Unlocked: Yes

Normal filenames such as Desktop, Documents, and .config should become visible.

Return to the graphical login screen with Ctrl + Alt + F1 or Ctrl + Alt + F2, depending on the Linux distribution, and try signing in again.

Permission Denied When Running fscrypt unlock

Running fscrypt unlock without elevated permissions may produce an error similar to:

open /.fscrypt/policies/<policy-id>: permission denied

Use sudo and provide the Swif-managed key file:

sudo fscrypt unlock /home/<username> \   
--key=/var/lib/swifteam/fscrypt/<username>.key

If the protector is described as a raw key protector, the user’s normal login password cannot unlock the directory. Do not repeatedly enter the login password when fscrypt requests a key file.

The Key File Is Missing

If the key, unlock script, or other expected files are missing, stop troubleshooting and contact Swif Support.

Do not:

  • Generate a new key

  • Run fscrypt encrypt again

  • Delete or rename the encrypted home directory

  • Create a replacement directory at the same path

  • Run file-recovery tools against the mounted system disk

  • Perform large downloads, installations, or file copies

A newly generated key cannot unlock data encrypted with the original key. The files may still be present on disk, but their contents and filenames cannot be decrypted without recovering the original key.

To collect non-sensitive diagnostic information, run:

sudo ls -la /var/lib/swifteam/fscrypt/ 
sudo ls -ld /home/<username> \
/home/<username>.bak.* \
/home/<username>.new.* \
/home/<username>.encrypted.* \
/home/<username>.decrypted.* 2>/dev/null
sudo systemctl status 'swif-fscrypt-unlock@<username>.service'
df -hT /var/lib/swifteam /home/<username>
lsblk -f

Some shells report no matches found when no backup directory matches a wildcard. This only means that no matching path was found.

Send the command output to Swif Support. Do not send encryption-key contents.

Searching the missing key

Search for any leftover copy of the key

sudo find /var /tmp /root /opt /etc /home -name '*<username>*.key' -o -name '<username>.key' -o -name 'swif-fscrypt-*' 2>/dev/null
sudo ls -la /var/lib/swifteam/backup /var/tmp /tmp 2>/dev/null
ls /timeshift 2>/dev/null
sudo btrfs subvolume list / 2>/dev/null | head

Try recovering the deleted 32-byte file (ext4)
​
The key was a 32-byte file with path:
​/var/lib/swifteam/fscrypt/<username>.key
​
If df shows ext4 for /var:

# replace /dev/sdX with the device from df, e.g. /dev/nvme0n1p2 or /dev/mapper/...
DEV=$(df --output=source /var/lib/swifteam | tail -1)
echo "device=$DEV"
sudo debugfs -R 'ls -l /var/lib/swifteam/fscrypt' "$DEV"
sudo debugfs -R 'lsdel' "$DEV" | head -n 50

Then, only if you are comfortable installing a recovery tool:

sudo apt-get install -y extundelete testdisk
sudo mkdir -p /home/ksa/recovery
sudo extundelete "$DEV" --restore-file var/lib/swifteam/fscrypt/<username>.key --output-dir /home/ksa/recovery
ls -la /home/ksa/recovery


If that restores a file, check size:

stat -c '%s %n' /home/ksa/recovery/*/<username>.key /home/ksa/recovery/<username>.key 2>/dev/null

It must be exactly 32 bytes. If it is, unlock with:

sudo fscrypt unlock /home/<username> --key=/THE/RECOVERED/<username>.key
sudo fscrypt status /home/<username>
ls /home/<username> | head

If undelete finds nothing
The safer option is to stop using this disk for writes, boot a USB live session. Learn more here.

Replacing the Home Directory After Accepting Data Loss

If the original key cannot be recovered, the encrypted data cannot be decrypted with the login password or a newly generated key.

An administrator can remove the inaccessible encrypted home and create a new home directory, but this is not data recovery. It permanently abandons the encrypted data.

Before taking this action:

  • Obtain explicit approval from the device owner or organization.

  • Confirm that no required backup exists.

  • Preserve a disk image if future recovery may be attempted.

  • Verify the user’s UID and GID.

  • Contact Swif Support for commands appropriate to the device.

Do not delete the encrypted home directory merely to restore graphical login unless the loss of its contents has been reviewed and accepted.

After Restoring Access

After the home directory is unlocked:

  1. Confirm that normal filenames and files are accessible.

  2. Verify that the user can sign in graphically.

  3. Restart the device and test another login.

  4. Confirm that the unlock service runs successfully.

  5. Review the policy assignment and device status in Swif.

  6. Contact Swif Support if the directory becomes locked again.

For additional information about fscrypt, see the official fscrypt documentation.


Recovering a Missing Key with a USB live session

If the Swif-managed key file is missing, the home directory may still contain encrypted files even though the user cannot sign in. A missing unlock script or disabled unlock service can also prevent automatic access, but recreating those components does not replace a lost key.

For example, an affected user named kenn may have:

  • No /var/lib/swifteam/fscrypt/kenn.key.

  • A missing automatic-unlock script.

  • A disabled swif-fscrypt-unlock@kenn.service.

  • No /home/kenn.bak.* backup directory.

The steps below use kenn as an example. Replace it with the affected username. Disk partitions, logical volumes, and mount paths must also be identified on the actual device.

Understand What Must Be Recovered

An fscrypt raw-key protector requires the original 32-byte binary key, along with the filesystem’s encryption metadata. A login password cannot substitute for that raw key. If fscrypt status shows another valid protector, it may provide an alternative unlock method. See the official fscrypt documentation.

Do not generate a replacement key, run fscrypt encrypt again, delete the encrypted home, or remove its .fscrypt metadata. A new key cannot decrypt the existing data.

If the home is currently unlocked and files are readable, do not reboot or deliberately lock it. Preserve accessible files to secure external storage and contact Swif Support first. The following procedure addresses an already locked home with a missing key.

1. Minimize Writes and Record the Storage Layout

Use an existing alternate administrator account in a text console for brief diagnostics. Avoid ordinary desktop use, creating users, installing packages, copying large files, or running disk cleanup/TRIM on the affected storage.

If local recovery access is available, temporarily stop the agent to reduce its activity:

sudo systemctl stop swif-agent.service

This can interrupt Swif management and reporting. It does not stop other system services from writing to disk. If the service name differs or remote management is your only access route, coordinate with Support before stopping it.

Collect these details without displaying key contents:

sudo fscrypt status /home/kenn
sudo ls -la /var/lib/swifteam/fscrypt/
sudo cat -A /var/lib/swifteam/fscrypt/managed-users
sudo systemctl status swif-fscrypt-unlock@kenn.service --no-pager
df -hT /var/lib/swifteam /home/kenn
findmnt -T /var/lib/swifteam
lsblk -f

Record the approximate deletion time and timezone if known. Photograph the output or save it externally rather than writing diagnostic files to the affected disk.

Recover the filesystem that contained the key file. This may be the root filesystem or a separate /var filesystem, even when the encrypted home is on another volume.

2. Boot a Trusted Live USB

If the home is locked and recovery is needed:

  1. Shut down the installed operating system.

  2. Boot trusted Ubuntu live media using the device’s boot menu.

  3. Choose Try Ubuntu, not installation.

  4. Open a terminal and run lsblk -f.

  5. Connect a separate external drive for images and recovery output.

Do not open the internal disk in the file manager, which may mount it automatically. Check mountpoints before proceeding.

Keeping an alternate account open on the installed system is not a safe long-term recovery environment. Background writes can overwrite deleted data. The extundelete project recommends an unmounted source and a separate destination. See extundelete recovery guidance.

3. Open Disk Encryption, If Present

Full-disk encryption and home-directory encryption are separate layers:

Layer

Required credential

What it unlocks

LUKS disk encryption

Disk passphrase, recovery credential, or existing supported token

Access to the contained filesystem or LVM storage

fscrypt raw-key home encryption

Original raw key or another valid protector

The home directory’s filenames and contents

For a device whose verified LUKS partition is /dev/nvme0n1p6, an example read-only mapping is:

sudo cryptsetup open --type luks --readonly /dev/nvme0n1p6 cryptubuntu

Use the disk-unlock passphrase when prompted, which is not necessarily the desktop password. The --readonly option creates a read-only mapping. See cryptsetup open documentation.

If the mapped device contains LVM, identify and activate the correct volume group. For a group actually named ubuntu-vg:

sudo vgscan
sudo vgchange -ay ubuntu-vg
lsblk -f

An example logical-volume path is /dev/mapper/ubuntu--vg-ubuntu--lv. Use the path reported by the device, not an assumed partition or volume name.

No password prompt does not automatically mean failure; check whether the mapping exists. If the system relies on Clevis/TPM unlocking, have Support review its existing binding and live-environment requirements. Installing Clevis alone does not create a recovery credential, and it cannot recover the missing fscrypt key.

4. Search Existing Files and Backups Without Replaying the Journal

For the rest of this example, assume the root filesystem is ext4 and contains both /var/lib/swifteam and /home/kenn:

KEY_FS=/dev/mapper/ubuntu--vg-ubuntu--lv
sudo mkdir -p /mnt/installed
sudo mount -t ext4 -o ro,noload "$KEY_FS" /mnt/installed

Only use this value after verifying the device. If /var or /home is separate, adapt the mounts and paths with Support.

For ext4, ro alone can still replay the journal. ro,noload prevents that replay, although an unclean filesystem may appear inconsistent. If mounting fails, stop rather than trying a writable mount or repairing the original filesystem. See the Linux kernel’s ext4 documentation.

Search the installed filesystem:

sudo find /mnt/installed -xdev \
\( -name '*kenn*.key' -o -name 'swif-fscrypt-*' \) -print

sudo find /mnt/installed/home -maxdepth 1 -type d \
-name 'kenn.bak.*' -print

sudo ls -la /mnt/installed/var/lib/swifteam/backup \
/mnt/installed/var/tmp /mnt/installed/tmp 2>/dev/null

The search stays on that filesystem. Search separately mounted filesystems and external backups separately. Review any pre-existing snapshots that actually included the key’s location; do not create a new snapshot on the affected disk. A Btrfs subvolume list is not an ext4 recovery method, and a Timeshift snapshot may exclude relevant paths.

If a candidate key is found, note its path and securely preserve a copy externally. Do not print its contents or open it in an editor. A missing backup directory does not prove that no external backup exists.

When finished, unmount the source:

sudo umount /mnt/installed 
lsblk -f

5. Attempt ext4 Recovery From an Image

If no copy is found, preserve an image before recovery attempts. For important data or a disk showing read errors, use a qualified recovery specialist.

The example below assumes:

  • KEY_FS identifies the unmounted ext4 filesystem containing the deleted key.

  • A separate external drive is mounted at /mnt/recovery.

  • The destination has enough free space for the entire source filesystem image and recovered files.

  • The image and map filenames are new and reserved for this source.

Verify the destination with findmnt -T /mnt/recovery and df -h /mnt/recovery. Stop if the external drive is not mounted there or the destination is on the affected disk.

Install tools in the live session, not inside the installed system:

sudo apt-get update 
sudo apt-get install gddrescue extundelete

Create a filesystem image on the external drive:

sudo ddrescue -n "$KEY_FS" \
/mnt/recovery/key-filesystem.img \
/mnt/recovery/key-filesystem.map

Review the result. Do not interpret an incomplete image as proof that the key is unrecoverable. The image can contain sensitive information, including data exposed by opening LUKS; protect the external drive accordingly.

Run extundelete against the unmounted image, writing output externally:

sudo mkdir -p /mnt/recovery/key-restore
cd /mnt/recovery/key-restore
sudo extundelete /mnt/recovery/key-filesystem.img \
--restore-file var/lib/swifteam/fscrypt/kenn.key

The restore path is relative to the root of the imaged filesystem:

Filesystem containing the key

Relative restore path

Root /

var/lib/swifteam/fscrypt/kenn.key

Separate /var

lib/swifteam/fscrypt/kenn.key

Separate /var/lib/swifteam

fscrypt/kenn.key

By default, recovered files are placed under RECOVERED_FILES in the working directory. Recovery is not guaranteed, and extundelete may not handle every modern ext4 feature. See the extundelete command reference.

If extundelete Warns About an Unmounted or Unclean Filesystem

Stop if it reports EXT3_FEATURE_INCOMPAT_RECOVER, requests unmounting, or recommends running fsck.

Confirm that you are using the intended image and that it is not mounted. The warning can persist on an image because it preserves the original filesystem’s unclean state.

Do not run fsck on the original disk to clear the warning. Keep the original image unchanged. Have Support or a recovery specialist evaluate a separate working copy before journal replay, repair, or further attempts.

Do not save recovered files under another user’s home on the affected filesystem. That can overwrite the deleted key’s blocks.

6. Validate and Test a Recovered Key

Locate candidate files without displaying their contents:

sudo find /mnt/recovery/key-restore -type f -name 'kenn.key' \
-exec stat -c '%s %n' {} \;

The expected key is exactly 32 bytes. Size alone does not establish that it is the correct key. Do not truncate, pad, or convert a recovered file to make its size match.

After preserving the image, mount the original ext4 filesystem read-only again for a controlled unlock test. For the example where root contains the home and its fscrypt metadata:

sudo mount -t ext4 -o ro,noload "$KEY_FS" /mnt/installed
sudo fscrypt unlock /mnt/installed/home/kenn \
--key=/mnt/recovery/key-restore/RECOVERED_FILES/var/lib/swifteam/fscrypt/kenn.key
sudo fscrypt status /mnt/installed/home/kenn

Use the actual recovered path. Install fscrypt in the live environment if needed. If the home is on a separate filesystem, mount that filesystem and preserve its .fscrypt metadata; the example path must be adjusted.

Success should show Unlocked: Yes and allow normal filenames and files to be read. Back up accessible data to secure external storage before attempting service repairs or normal use.

If the key is rejected, keep all candidates and the image. A same-sized file, a damaged key, or missing encryption metadata can prevent unlocking. See fscrypt’s recovery and metadata guidance.

7. Restore Automatic Unlocking or Plan a Fresh Home

After successful recovery, work with Swif Support to restore the key’s expected path and permissions, the missing unlock script, and the per-user service. A successful manual unlock does not fix automatic unlocking. Preserve the recovered key and data backup before testing a reboot, then confirm agent operation and policy status.

If recovery finds nothing, preserve the disk and image. Further writes or discarded SSD blocks may make recovery impossible. PhotoRec is not a guaranteed fallback for a small random binary key; it primarily identifies files by recognizable formats. See PhotoRec’s recovery overview.

If no original key, usable alternative protector, or readable backup is available, recreating the desktop requires a separate decision to abandon the inaccessible home. Follow Replacing the Home Directory After Accepting Data Loss in this article.

Deleting /home/kenn and copying /etc/skel creates a fresh home. It does not recover encrypted files. Do not include that operation in the key-recovery procedure. Any later rebuild must verify both the user’s UID and GID rather than assuming 1000:1000.

When contacting Support, provide the filesystem layout, approximate deletion time, tool errors, and candidate file paths and sizes. Do not send key contents, disk passphrases, or private files through ordinary chat or email.


Known Limitations

Limitation

Details

Logged-in users cannot be encrypted

Encryption is skipped for any user currently logged in to avoid file corruption. The user must be logged out for encryption to proceed.

ext4 file systems only

Other Linux file systems (e.g., btrfs, xfs) are not supported.

ecryptfs is legacy

The older ecryptfs method (which uses /home/.ecryptfs/<username>/.Private) is not used. This policy uses fscrypt exclusively.

TPM-enabled devices

Devices with TPM enabled are not compatible with this policy. For TPM-based full disk encryption, refer to your distribution's documentation.


Troubleshooting

Active Session Encryption

If you encounter the error `encrypt user home "<username>": user has an active login session; retry after logout`, it indicates that the encryption process was skipped because the target user is currently logged in. To prevent data corruption, the policy only applies when the user is logged out.

To resolve this and ensure the home directory is encrypted:

  1. Restart the device.

  2. Log in as a different user (or a temporary administrative user).

  3. Wait for 3 minutes to allow the Swif agent to complete the encryption process in the background.

  4. Log back in as the target user.

Once these steps are completed, the device will report the encryption status as active in the Swif console.

Frequently Asked Questions

Q: What happens if allUsers is true and I also provide a userList?
A: The userList is ignored. When allUsers is enabled, encryption management applies to every user on the device.

Q: Why does encryption only run when the user is logged out?
A: Encrypting a home directory while the user is actively logged in could cause data corruption or session instability. The agent waits until the user logs out before performing encryption operations.

Q: Which encryption method is used?
A: This policy uses fscrypt (Linux native file-system-level encryption). The agent verifies encryption status via sudo fscrypt status /home/<username>.

Q: Does this work on non-ext4 file systems?
A: No. Currently only ext4 file systems are supported. Home directories on btrfs, xfs, or other file systems will not be managed.

Q: Why isn't my home directory encrypted even though the policy is assigned?
A: The most common reason is that you are currently logged in. Log out, have another user log in (or restart the device and log in as a different user), and the encryption will be applied to your home directory.

Q: Do I need to reinstall my OS to use this policy?
A: No. Unlike full disk encryption, home directory encryption can be applied to existing installations without reinstalling the operating system.

Q: What happens if I assign an empty user list?
A: No home directories will be encrypted. This effectively disables the policy without removing it.

Q: How do I encrypt all users' home directories?
A: Set allUsers to true.


Did this answer your question?