xref: /freebsd/sys/contrib/openzfs/man/man8/pam_zfs_key.8 (revision 8a62a2a5659d1839d8799b4274c04469d7f17c78)
1.\" SPDX-License-Identifier: BSD-3-Clause
2.\"
3.\" Copyright (c) 2020, Felix Dörre
4.\" All rights reserved.
5.\"
6.Dd December 24, 2025
7.Dt PAM_ZFS_KEY 8
8.Os
9.
10.Sh NAME
11.Nm pam_zfs_key
12.Nd PAM module for ZFS encryption key management
13.Sh SYNOPSIS
14.Nm pam_zfs_key.so
15.Op Ar options
16.
17.Sh DESCRIPTION
18.Nm
19is a PAM module that automatically manages encryption keys for ZFS
20datasets during user authentication and session management.
21When a user logs in, the module uses their password to unlock their encrypted
22home directory.
23When the last session closes, the module unmounts the dataset and unloads
24the key.
25.Pp
26The module tracks active sessions using reference counting to support multiple
27simultaneous logins from the same user.
28.Ss Multiple Home Prefixes
29When configured with multiple home prefixes, the module attempts operations
30on all matching datasets.
31Operations that succeed are not rolled back if others fail.
32The module returns success only if all operations succeed.
33.Pp
34For example, with datasets 1, 2, 3 where dataset 2 fails:
35.Bl -bullet -compact
36.It
37Auth/session: datasets 1 and 3 are unlocked and mounted, dataset 2 is not.
38.It
39Password change: datasets 1 and 3 have the new password,
40dataset 2 retains the old.
41.El
42.Pp
43With
44.Sy required ,
45login fails even though datasets 1 and 3 succeeded.
46With
47.Sy optional ,
48login proceeds.
49For password changes, datasets 1 and 3 are updated while dataset 2
50retains the old password.
51With
52.Sy required ,
53the user sees an error.
54With
55.Sy optional ,
56the user sees success and may not notice the inconsistency.
57Either way, passwords are left out of sync.
58.Pp
59Errors are logged to syslog.
60Use
61.Xr zfs-change-key 8
62to resync passwords after partial failure.
63.
64.Sh OPTIONS
65.Bl -tag -width "mount_recursively"
66.It Sy homes Ns = Ns Ar path Ns Oo , Ns Ar path2 Ns ... Oc
67Comma-separated list of dataset prefixes where user home directories
68are located.
69The module constructs the full dataset path as
70.Ar prefix Ns / Ns Ar username .
71Default:
72.Sy zroot/home
73on
74.Fx ,
75.Sy rpool/home
76on Linux.
77.It Sy runstatedir Ns = Ns Ar path
78Directory for storing session reference counts.
79Default:
80.Pa /var/run/pam_zfs_key .
81.It Sy uid_min Ns = Ns Ar uid
82Minimum user ID for which the module will operate.
83Default: 1000.
84.It Sy uid_max Ns = Ns Ar uid
85Maximum user ID for which the module will operate.
86Default: MAXUID.
87.It Sy nounmount
88Do not unmount datasets or unload encryption keys when sessions close.
89Datasets remain mounted and keys remain loaded.
90.It Sy forceunmount
91Force unmount datasets even if busy
92.Pq Dv MS_FORCE .
93.It Sy recursive_homes
94Recursively search for encrypted datasets under the homes prefix.
95.It Sy mount_recursively
96Mount and unmount child datasets recursively.
97.It Sy prop_mountpoint
98Find the user's dataset by matching the dataset's
99.Sy mountpoint
100property to the user's home directory from
101.Pa /etc/passwd ,
102instead of constructing the dataset name as
103.Ar prefix Ns / Ns Ar username .
104.El
105.
106.Sh FILES
107.Bl -tag -width Pa
108.It Pa /var/run/pam_zfs_key/ Ns Ar uid
109Session reference count files tracking active logins per user.
110.El
111.
112.Sh EXAMPLES
113.Ss Example 1: Basic Configuration
114Add to
115.Pa /etc/pam.d/system-auth :
116.Bd -literal -offset indent
117auth     optional  pam_zfs_key.so
118password optional  pam_zfs_key.so
119session  optional  pam_zfs_key.so
120.Ed
121.Pp
122This configuration uses default settings.
123User home datasets are expected at
124.Sy zroot/home/ Ns Ar username
125on
126.Fx
127or
128.Sy rpool/home/ Ns Ar username
129on Linux.
130.
131.Ss Example 2: Custom Home Directory Prefix
132.Bd -literal -offset indent
133auth     optional  pam_zfs_key.so homes=tank/users
134password optional  pam_zfs_key.so homes=tank/users
135session  optional  pam_zfs_key.so homes=tank/users
136.Ed
137.Pp
138Looks for user datasets at
139.Sy tank/users/ Ns Ar username .
140.
141.Ss Example 3: Multiple Dataset Prefixes
142.Bd -literal -offset indent
143session  optional  pam_zfs_key.so homes=rpool/home,tank/users
144.Ed
145.Pp
146Searches for user datasets in both
147.Sy rpool/home
148and
149.Sy tank/users .
150.
151.Ss Example 4: Keep Datasets Mounted
152.Bd -literal -offset indent
153session  optional  pam_zfs_key.so nounmount
154.Ed
155.Pp
156Leaves datasets mounted and keys loaded when sessions close.
157Useful for systems with background processes accessing the home directory.
158.
159.Ss Example 5: Recursive Mounting
160.Bd -literal -offset indent
161session  optional  pam_zfs_key.so mount_recursively
162.Ed
163.Pp
164Mounts child datasets recursively, useful when user data is organized
165hierarchically like
166.Sy rpool/home/alice/documents
167and
168.Sy rpool/home/alice/photos .
169.
170.Ss Example 6: Creating an Encrypted Home Dataset
171.Bd -literal -offset indent
172# zfs create -o encryption=on \e
173    -o keyformat=passphrase \e
174    -o keylocation=prompt \e
175    -o canmount=on \e
176    -o mountpoint=/home/alice \e
177    rpool/home/alice
178.Ed
179.Pp
180The user's login password must match the dataset passphrase for automatic
181unlocking to work.
182The dataset must have a ZFS-managed mountpoint (not legacy) and
183.Sy canmount Ns = Ns Sy on
184for automatic mounting.
185.
186.Ss Example 7: Multiple Homes with Password Sync Check
187.Bd -literal -offset indent
188auth     optional  pam_zfs_key.so homes=rpool/home,tank/home
189password required  pam_zfs_key.so homes=rpool/home,tank/home
190session  optional  pam_zfs_key.so homes=rpool/home,tank/home
191.Ed
192.Pp
193Login proceeds even if some datasets are unavailable.
194Password changes fail if any dataset cannot be updated, ensuring
195the user is notified of sync issues.
196See
197.Sx Multiple Home Prefixes
198for failure behavior.
199.
200.Sh SEE ALSO
201.Xr pam 8 ,
202.Xr zfs-change-key 8 ,
203.Xr zfs-load-key 8 ,
204.Xr zfs-mount 8
205.
206.Sh NOTES
207.Bl -bullet -compact
208.It
209Only works with datasets using
210.Sy keyformat Ns = Ns Sy passphrase .
211.It
212Datasets must have
213.Sy keylocation Ns = Ns Sy prompt .
214.It
215Datasets with
216.Sy mountpoint Ns = Ns Sy legacy ,
217.Sy canmount Ns = Ns Sy off ,
218or
219.Sy canmount Ns = Ns Sy noauto
220will have keys loaded but not be automatically mounted.
221.El
222