pam_zfs_key.8

PAM_ZFS_KEY(8) System Manager's Manual PAM_ZFS_KEY(8)

pam_zfs_keyPAM module for ZFS encryption key management

pam_zfs_key.so [options]

pam_zfs_key is a PAM module that automatically manages encryption keys for ZFS datasets during user authentication and session management. When a user logs in, the module uses their password to unlock their encrypted home directory. When the last session closes, the module unmounts the dataset and unloads the key.

The module tracks active sessions using reference counting to support multiple simultaneous logins from the same user.

When configured with multiple home prefixes, the module attempts operations on all matching datasets. Operations that succeed are not rolled back if others fail. The module returns success only if all operations succeed.

For example, with datasets 1, 2, 3 where dataset 2 fails:

  • Auth/session: datasets 1 and 3 are unlocked and mounted, dataset 2 is not.
  • Password change: datasets 1 and 3 have the new password, dataset 2 retains the old.

With required, login fails even though datasets 1 and 3 succeeded. With optional, login proceeds. For password changes, datasets 1 and 3 are updated while dataset 2 retains the old password. With required, the user sees an error. With optional, the user sees success and may not notice the inconsistency. Either way, passwords are left out of sync.

Errors are logged to syslog. Use zfs-change-key(8) to resync passwords after partial failure.

=path[,path2...]
Comma-separated list of dataset prefixes where user home directories are located. The module constructs the full dataset path as prefix/username. Default: on FreeBSD, rpool/home on Linux.
=path
Directory for storing session reference counts. Default: /var/run/pam_zfs_key.
=uid
Minimum user ID for which the module will operate. Default: 1000.
=uid
Maximum user ID for which the module will operate. Default: MAXUID.
Do not unmount datasets or unload encryption keys when sessions close. Datasets remain mounted and keys remain loaded.
Force unmount datasets even if busy (MS_FORCE).
Recursively search for encrypted datasets under the homes prefix.
Mount and unmount child datasets recursively.
Find the user's dataset by matching the dataset's mountpoint property to the user's home directory from /etc/passwd, instead of constructing the dataset name as prefix/username.

/var/run/pam_zfs_key/uid
Session reference count files tracking active logins per user.

Add to /etc/pam.d/system-auth:

auth     optional  pam_zfs_key.so
password optional  pam_zfs_key.so
session  optional  pam_zfs_key.so

This configuration uses default settings. User home datasets are expected at username on FreeBSD or username on Linux.

auth     optional  pam_zfs_key.so homes=tank/users
password optional  pam_zfs_key.so homes=tank/users
session  optional  pam_zfs_key.so homes=tank/users

Looks for user datasets at username.

session  optional  pam_zfs_key.so homes=rpool/home,tank/users

Searches for user datasets in both rpool/home and .

session  optional  pam_zfs_key.so nounmount

Leaves datasets mounted and keys loaded when sessions close. Useful for systems with background processes accessing the home directory.

session  optional  pam_zfs_key.so mount_recursively

Mounts child datasets recursively, useful when user data is organized hierarchically like and .

# zfs create -o encryption=on \
    -o keyformat=passphrase \
    -o keylocation=prompt \
    -o canmount=on \
    -o mountpoint=/home/alice \
    rpool/home/alice

The user's login password must match the dataset passphrase for automatic unlocking to work. The dataset must have a ZFS-managed mountpoint (not legacy) and canmount= for automatic mounting.

auth     optional  pam_zfs_key.so homes=rpool/home,tank/home
password required  pam_zfs_key.so homes=rpool/home,tank/home
session  optional  pam_zfs_key.so homes=rpool/home,tank/home

Login proceeds even if some datasets are unavailable. Password changes fail if any dataset cannot be updated, ensuring the user is notified of sync issues. See Multiple Home Prefixes for failure behavior.

zfs-change-key(8), zfs-load-key(8), zfs-mount(8)

December 24, 2025 Debian