1CRYPTTAB(5)                        crypttab                        CRYPTTAB(5)
2
3
4

NAME

6       crypttab - Configuration for encrypted block devices
7

SYNOPSIS

9       /etc/crypttab
10

DESCRIPTION

12       The /etc/crypttab file describes encrypted block devices that are set
13       up during system boot.
14
15       Empty lines and lines starting with the "#" character are ignored. Each
16       of the remaining lines describes one encrypted block device. Fields are
17       delimited by white space.
18
19       Each line is in the form
20
21           volume-name encrypted-device key-file options
22
23       The first two fields are mandatory, the remaining two are optional.
24
25       Setting up encrypted block devices using this file supports three
26       encryption modes: LUKS, TrueCrypt and plain. See cryptsetup(8) for more
27       information about each mode. When no mode is specified in the options
28       field and the block device contains a LUKS signature, it is opened as a
29       LUKS device; otherwise, it is assumed to be in raw dm-crypt (plain
30       mode) format.
31
32       The first field contains the name of the resulting encrypted volume;
33       its block device is set up below /dev/mapper/.
34
35       The second field contains a path to the underlying block device or
36       file, or a specification of a block device via "UUID=" followed by the
37       UUID.
38
39       The third field specifies an absolute path to a file to read the
40       encryption key from. Optionally, the path may be followed by ":" and an
41       fstab device specification (e.g. starting with "LABEL=" or similar); in
42       which case, the path is relative to the device file system root. If the
43       field is not present or set to "none" or "-", a key file named after
44       the volume to unlock (i.e. the first column of the line), suffixed with
45       .key is automatically loaded from the /etc/cryptsetup-keys.d/ and
46       /run/cryptsetup-keys.d/ directories, if present. Otherwise, the
47       password has to be manually entered during system boot. For swap
48       encryption, /dev/urandom may be used as key file.
49
50       The fourth field, if present, is a comma-delimited list of options. The
51       following options are recognized:
52
53       cipher=
54           Specifies the cipher to use. See cryptsetup(8) for possible values
55           and the default value of this option. A cipher with unpredictable
56           IV values, such as "aes-cbc-essiv:sha256", is recommended.
57
58       discard
59           Allow discard requests to be passed through the encrypted block
60           device. This improves performance on SSD storage but has security
61           implications.
62
63       hash=
64           Specifies the hash to use for password hashing. See cryptsetup(8)
65           for possible values and the default value of this option.
66
67       header=
68           Use a detached (separated) metadata device or file where the LUKS
69           header is stored. This option is only relevant for LUKS devices.
70           See cryptsetup(8) for possible values and the default value of this
71           option.
72
73       keyfile-offset=
74           Specifies the number of bytes to skip at the start of the key file.
75           See cryptsetup(8) for possible values and the default value of this
76           option.
77
78       keyfile-size=
79           Specifies the maximum number of bytes to read from the key file.
80           See cryptsetup(8) for possible values and the default value of this
81           option. This option is ignored in plain encryption mode, as the key
82           file size is then given by the key size.
83
84       keyfile-erase
85           If enabled, the specified key file is erased after the volume is
86           activated or when activation fails. This is in particular useful
87           when the key file is only acquired transiently before activation
88           (e.g. via a file in /run/, generated by a service running before
89           activation), and shall be removed after use. Defaults to off.
90
91       key-slot=
92           Specifies the key slot to compare the passphrase or key against. If
93           the key slot does not match the given passphrase or key, but
94           another would, the setup of the device will fail regardless. This
95           option implies luks. See cryptsetup(8) for possible values. The
96           default is to try all key slots in sequential order.
97
98       keyfile-timeout=
99           Specifies the timeout for the device on which the key file resides
100           and falls back to a password if it could not be mounted. See
101           systemd-cryptsetup-generator(8) for key files on external devices.
102
103       luks
104           Force LUKS mode. When this mode is used, the following options are
105           ignored since they are provided by the LUKS header on the device:
106           cipher=, hash=, size=.
107
108       bitlk
109           Decrypt Bitlocker drive. Encryption parameters are deduced by
110           cryptsetup from Bitlocker header.
111
112       _netdev
113           Marks this cryptsetup device as requiring network. It will be
114           started after the network is available, similarly to
115           systemd.mount(5) units marked with _netdev. The service unit to set
116           up this device will be ordered between remote-fs-pre.target and
117           remote-cryptsetup.target, instead of cryptsetup-pre.target and
118           cryptsetup.target.
119
120           Hint: if this device is used for a mount point that is specified in
121           fstab(5), the _netdev option should also be used for the mount
122           point. Otherwise, a dependency loop might be created where the
123           mount point will be pulled in by local-fs.target, while the service
124           to configure the network is usually only started after the local
125           file system has been mounted.
126
127       noauto
128           This device will not be added to cryptsetup.target. This means that
129           it will not be automatically unlocked on boot, unless something
130           else pulls it in. In particular, if the device is used for a mount
131           point, it'll be unlocked automatically during boot, unless the
132           mount point itself is also disabled with noauto.
133
134       nofail
135           This device will not be a hard dependency of cryptsetup.target.
136           It'll still be pulled in and started, but the system will not wait
137           for the device to show up and be unlocked, and boot will not fail
138           if this is unsuccessful. Note that other units that depend on the
139           unlocked device may still fail. In particular, if the device is
140           used for a mount point, the mount point itself also needs to have
141           the nofail option, or the boot will fail if the device is not
142           unlocked successfully.
143
144       offset=
145           Start offset in the backend device, in 512-byte sectors. This
146           option is only relevant for plain devices.
147
148       plain
149           Force plain encryption mode.
150
151       read-only, readonly
152           Set up the encrypted block device in read-only mode.
153
154       same-cpu-crypt
155           Perform encryption using the same cpu that IO was submitted on. The
156           default is to use an unbound workqueue so that encryption work is
157           automatically balanced between available CPUs.
158
159           This requires kernel 4.0 or newer.
160
161       submit-from-crypt-cpus
162           Disable offloading writes to a separate thread after encryption.
163           There are some situations where offloading write requests from the
164           encryption threads to a dedicated thread degrades performance
165           significantly. The default is to offload write requests to a
166           dedicated thread because it benefits the CFQ scheduler to have
167           writes submitted using the same context.
168
169           This requires kernel 4.0 or newer.
170
171       no-read-workqueue
172           Bypass dm-crypt internal workqueue and process read requests
173           synchronously. The default is to queue these requests and process
174           them asynchronously.
175
176           This requires kernel 5.9 or newer.
177
178       no-write-workqueue
179           Bypass dm-crypt internal workqueue and process write requests
180           synchronously. The default is to queue these requests and process
181           them asynchronously.
182
183           This requires kernel 5.9 or newer.
184
185       skip=
186           How many 512-byte sectors of the encrypted data to skip at the
187           beginning. This is different from the offset= option with respect
188           to the sector numbers used in initialization vector (IV)
189           calculation. Using offset= will shift the IV calculation by the
190           same negative amount. Hence, if offset=n is given, sector n will
191           get a sector number of 0 for the IV calculation. Using skip= causes
192           sector n to also be the first sector of the mapped device, but with
193           its number for IV generation being n.
194
195           This option is only relevant for plain devices.
196
197       size=
198           Specifies the key size in bits. See cryptsetup(8) for possible
199           values and the default value of this option.
200
201       sector-size=
202           Specifies the sector size in bytes. See cryptsetup(8) for possible
203           values and the default value of this option.
204
205       swap
206           The encrypted block device will be used as a swap device, and will
207           be formatted accordingly after setting up the encrypted block
208           device, with mkswap(8). This option implies plain.
209
210           WARNING: Using the swap option will destroy the contents of the
211           named partition during every boot, so make sure the underlying
212           block device is specified correctly.
213
214       tcrypt
215           Use TrueCrypt encryption mode. When this mode is used, the
216           following options are ignored since they are provided by the
217           TrueCrypt header on the device or do not apply: cipher=, hash=,
218           keyfile-offset=, keyfile-size=, size=.
219
220           When this mode is used, the passphrase is read from the key file
221           given in the third field. Only the first line of this file is read,
222           excluding the new line character.
223
224           Note that the TrueCrypt format uses both passphrase and key files
225           to derive a password for the volume. Therefore, the passphrase and
226           all key files need to be provided. Use tcrypt-keyfile= to provide
227           the absolute path to all key files. When using an empty passphrase
228           in combination with one or more key files, use "/dev/null" as the
229           password file in the third field.
230
231       tcrypt-hidden
232           Use the hidden TrueCrypt volume. This option implies tcrypt.
233
234           This will map the hidden volume that is inside of the volume
235           provided in the second field. Please note that there is no
236           protection for the hidden volume if the outer volume is mounted
237           instead. See cryptsetup(8) for more information on this limitation.
238
239       tcrypt-keyfile=
240           Specifies the absolute path to a key file to use for a TrueCrypt
241           volume. This implies tcrypt and can be used more than once to
242           provide several key files.
243
244           See the entry for tcrypt on the behavior of the passphrase and key
245           files when using TrueCrypt encryption mode.
246
247       tcrypt-system
248           Use TrueCrypt in system encryption mode. This option implies
249           tcrypt.
250
251       tcrypt-veracrypt
252           Check for a VeraCrypt volume. VeraCrypt is a fork of TrueCrypt that
253           is mostly compatible, but uses different, stronger key derivation
254           algorithms that cannot be detected without this flag. Enabling this
255           option could substantially slow down unlocking, because VeraCrypt's
256           key derivation takes much longer than TrueCrypt's. This option
257           implies tcrypt.
258
259       timeout=
260           Specifies the timeout for querying for a password. If no unit is
261           specified, seconds is used. Supported units are s, ms, us, min, h,
262           d. A timeout of 0 waits indefinitely (which is the default).
263
264       tmp=
265           The encrypted block device will be prepared for using it as /tmp/;
266           it will be formatted using mkfs(8). Takes a file system type as
267           argument, such as "ext4", "xfs" or "btrfs". If no argument is
268           specified defaults to "ext4". This option implies plain.
269
270           WARNING: Using the tmp option will destroy the contents of the
271           named partition during every boot, so make sure the underlying
272           block device is specified correctly.
273
274       tries=
275           Specifies the maximum number of times the user is queried for a
276           password. The default is 3. If set to 0, the user is queried for a
277           password indefinitely.
278
279       verify
280           If the encryption password is read from console, it has to be
281           entered twice to prevent typos.
282
283       pkcs11-uri=
284           Takes a RFC7512 PKCS#11 URI[1] pointing to a private RSA key which
285           is used to decrypt the key specified in the third column of the
286           line. This is useful for unlocking encrypted volumes through
287           security tokens or smartcards. See below for an example how to set
288           up this mechanism for unlocking a LUKS volume with a YubiKey
289           security token. The specified URI can refer directly to a private
290           RSA key stored on a token or alternatively just to a slot or token,
291           in which case a search for a suitable private RSA key will be
292           performed. In this case if multiple suitable objects are found the
293           token is refused. The key configured in the third column is passed
294           as is to RSA decryption. The resulting decrypted key is then base64
295           encoded before it is used to unlock the LUKS volume.
296
297       try-empty-password=
298           Takes a boolean argument. If enabled, right before asking the user
299           for a password it is first attempted to unlock the volume with an
300           empty password. This is useful for systems that are initialized
301           with an encrypted volume with only an empty password set, which
302           shall be replaced with a suitable password during first boot, but
303           after activation.
304
305       x-systemd.device-timeout=
306           Specifies how long systemd should wait for a device to show up
307           before giving up on the entry. The argument is a time in seconds or
308           explicitly specified units of "s", "min", "h", "ms".
309
310       x-initrd.attach
311           Setup this encrypted block device in the initramfs, similarly to
312           systemd.mount(5) units marked with x-initrd.mount.
313
314           Although it's not necessary to mark the mount entry for the root
315           file system with x-initrd.mount, x-initrd.attach is still
316           recommended with the encrypted block device containing the root
317           file system as otherwise systemd will attempt to detach the device
318           during the regular system shutdown while it's still in use. With
319           this option the device will still be detached but later after the
320           root file system is unmounted.
321
322           All other encrypted block devices that contain file systems mounted
323           in the initramfs should use this option.
324
325       At early boot and when the system manager configuration is reloaded,
326       this file is translated into native systemd units by systemd-
327       cryptsetup-generator(8).
328

EXAMPLES

330       Example 1. /etc/crypttab example
331
332       Set up four encrypted block devices. One using LUKS for normal storage,
333       another one for usage as a swap device and two TrueCrypt volumes.
334
335           luks       UUID=2505567a-9e27-4efe-a4d5-15ad146c258b
336           swap       /dev/sda7       /dev/urandom       swap
337           truecrypt  /dev/sda2       /etc/container_password  tcrypt
338           hidden     /mnt/tc_hidden  /dev/null    tcrypt-hidden,tcrypt-keyfile=/etc/keyfile
339           external   /dev/sda3       keyfile:LABEL=keydev keyfile-timeout=10s
340
341       Example 2. Yubikey-based Volume Unlocking Example
342
343       The PKCS#11 logic allows hooking up any compatible security token that
344       is capable of storing RSA decryption keys. Here's an example how to set
345       up a Yubikey security token for this purpose, using ykmap(1) from the
346       yubikey-manager project:
347
348           # Make sure no one can read the files we generate but us
349           umask 077
350
351           # Destroy any old key on the Yubikey (careful!)
352           ykman piv reset
353
354           # Generate a new private/public key pair on the device, store the public key in 'pubkey.pem'.
355           ykman piv generate-key -a RSA2048 9d pubkey.pem
356
357           # Create a self-signed certificate from this public key, and store it on the
358           # device. The "subject" should be an arbitrary string to identify the token in
359           # the p11tool output below.
360           ykman piv generate-certificate --subject "Knobelei" 9d pubkey.pem
361
362           # Check if the newly create key on the Yubikey shows up as token in PKCS#11. Have a look at the output, and
363           # copy the resulting token URI to the clipboard.
364           p11tool --list-tokens
365
366           # Generate a (secret) random key to use as LUKS decryption key.
367           dd if=/dev/urandom of=plaintext.bin bs=128 count=1
368
369           # Encode the secret key also as base64 text (with all whitespace removed)
370           base64 < plaintext.bin | tr -d '\n\r\t ' > plaintext.base64
371
372           # Encrypt this newly generated (binary) LUKS decryption key using the public key whose private key is on the
373           # Yubikey, store the result in /etc/cryptsetup-keys.d/mytest.key, where we'll look for it during boot.
374           mkdir -p /etc/cryptsetup-keys.d
375           sudo openssl rsautl -encrypt -pubin -inkey pubkey.pem -in plaintext.bin -out /etc/cryptsetup-keys.d/mytest.key
376
377           # Configure the LUKS decryption key on the LUKS device. We use very low pbkdf settings since the key already
378           # has quite a high quality (it comes directly from /dev/urandom after all), and thus we don't need to do much
379           # key derivation. Replace /dev/sdXn by the partition to use (e.g. sda1)
380           sudo cryptsetup luksAddKey /dev/sdXn plaintext.base64 --pbkdf=pbkdf2 --pbkdf-force-iterations=1000
381
382           # Now securely delete the plain text LUKS key, we don't need it anymore, and since it contains secret key
383           # material it should be removed from disk thoroughly.
384           shred -u plaintext.bin plaintext.base64
385
386           # We don't need the public key anymore either, let's remove it too. Since this one is not security
387           # sensitive we just do a regular "rm" here.
388           rm pubkey.pem
389
390           # Test: Let's run systemd-cryptsetup to test if this all worked. The option string should contain the full
391           # PKCS#11 URI we have in the clipboard; it tells the tool how to decipher the encrypted LUKS key. Note that
392           # systemd-cryptsetup automatically searches for the encrypted key in /etc/cryptsetup-keys.d/, hence we do
393           # not need to specify the key file path explicitly here.
394           sudo systemd-cryptsetup attach mytest /dev/sdXn - 'pkcs11-uri=pkcs11:...'
395
396           # If that worked, let's now add the same line persistently to /etc/crypttab, for the future.
397           sudo bash -c 'echo "mytest /dev/sdXn - \'pkcs11-uri=pkcs11:...\'" >> /etc/crypttab'
398
399       A few notes on the above:
400
401       ·   We use RSA (and not ECC), since Yubikeys support PKCS#11 Decrypt()
402           only for RSA keys
403
404       ·   We use RSA2048, which is the longest key size current Yubikeys
405           support
406
407       ·   LUKS key size must be shorter than 2048bit due to RSA padding,
408           hence we use 128 bytes
409
410       ·   We use Yubikey key slot 9d, since that's apparently the keyslot to
411           use for decryption purposes, see documentation[2].
412

SEE ALSO

414       systemd(1), systemd-cryptsetup@.service(8), systemd-cryptsetup-
415       generator(8), fstab(5), cryptsetup(8), mkswap(8), mke2fs(8)
416

NOTES

418        1. RFC7512 PKCS#11 URI
419           https://tools.ietf.org/html/rfc7512
420
421        2. see documentation
422           https://developers.yubico.com/PIV/Introduction/Certificate_slots.html
423
424
425
426systemd 246                                                        CRYPTTAB(5)
Impressum