1CRYPTTAB(5) crypttab CRYPTTAB(5)
2
3
4
6 crypttab - Configuration for encrypted block devices
7
9 /etc/crypttab
10
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 name encrypted-device password 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 block
33 device; the device is set up within /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 the encryption password. If the field is not
40 present or the password is set to "none" or "-", the password has to be
41 manually entered during system boot. Otherwise, the field is
42 interpreted as an absolute path to a file containing the encryption
43 password. For swap encryption, /dev/urandom or the hardware device
44 /dev/hw_random can be used as the password file; using /dev/random may
45 prevent boot completion if the system does not have enough entropy to
46 generate a truly random encryption key.
47
48 The fourth field, if present, is a comma-delimited list of options. The
49 following options are recognized:
50
51 cipher=
52 Specifies the cipher to use. See cryptsetup(8) for possible values
53 and the default value of this option. A cipher with unpredictable
54 IV values, such as "aes-cbc-essiv:sha256", is recommended.
55
56 discard
57 Allow discard requests to be passed through the encrypted block
58 device. This improves performance on SSD storage but has security
59 implications.
60
61 hash=
62 Specifies the hash to use for password hashing. See cryptsetup(8)
63 for possible values and the default value of this option.
64
65 header=
66 Use a detached (separated) metadata device or file where the LUKS
67 header is stored. This option is only relevant for LUKS devices.
68 See cryptsetup(8) for possible values and the default value of this
69 option.
70
71 keyfile-offset=
72 Specifies the number of bytes to skip at the start of the key file.
73 See cryptsetup(8) for possible values and the default value of this
74 option.
75
76 keyfile-size=
77 Specifies the maximum number of bytes to read from the key file.
78 See cryptsetup(8) for possible values and the default value of this
79 option. This option is ignored in plain encryption mode, as the key
80 file size is then given by the key size.
81
82 key-slot=
83 Specifies the key slot to compare the passphrase or key against. If
84 the key slot does not match the given passphrase or key, but
85 another would, the setup of the device will fail regardless. This
86 option implies luks. See cryptsetup(8) for possible values. The
87 default is to try all key slots in sequential order.
88
89 keyfile-timeout=
90 Specifies the timeout for the device on which the key file resides
91 and falls back to a password if it could not be mounted. See
92 systemd-cryptsetup-generator(8) for key files on external devices.
93
94 luks
95 Force LUKS mode. When this mode is used, the following options are
96 ignored since they are provided by the LUKS header on the device:
97 cipher=, hash=, size=.
98
99 _netdev
100 Marks this cryptsetup device as requiring network. It will be
101 started after the network is available, similarly to
102 systemd.mount(5) units marked with _netdev. The service unit to set
103 up this device will be ordered between remote-fs-pre.target and
104 remote-cryptsetup.target, instead of cryptsetup-pre.target and
105 cryptsetup.target.
106
107 Hint: if this device is used for a mount point that is specified in
108 fstab(5), the _netdev option should also be used for the mount
109 point. Otherwise, a dependency loop might be created where the
110 mount point will be pulled in by local-fs.target, while the service
111 to configure the network is usually only started after the local
112 file system has been mounted.
113
114 noauto
115 This device will not be added to cryptsetup.target. This means that
116 it will not be automatically unlocked on boot, unless something
117 else pulls it in. In particular, if the device is used for a mount
118 point, it'll be unlocked automatically during boot, unless the
119 mount point itself is also disabled with noauto.
120
121 nofail
122 This device will not be a hard dependency of cryptsetup.target.
123 It'll still be pulled in and started, but the system will not wait
124 for the device to show up and be unlocked, and boot will not fail
125 if this is unsuccessful. Note that other units that depend on the
126 unlocked device may still fail. In particular, if the device is
127 used for a mount point, the mount point itself also needs to have
128 the nofail option, or the boot will fail if the device is not
129 unlocked successfully.
130
131 offset=
132 Start offset in the backend device, in 512-byte sectors. This
133 option is only relevant for plain devices.
134
135 plain
136 Force plain encryption mode.
137
138 read-only, readonly
139 Set up the encrypted block device in read-only mode.
140
141 same-cpu-crypt
142 Perform encryption using the same cpu that IO was submitted on. The
143 default is to use an unbound workqueue so that encryption work is
144 automatically balanced between available CPUs.
145
146 This requires kernel 4.0 or newer.
147
148 submit-from-crypt-cpus
149 Disable offloading writes to a separate thread after encryption.
150 There are some situations where offloading write bios from the
151 encryption threads to a single thread degrades performance
152 significantly. The default is to offload write bios to the same
153 thread because it benefits CFQ to have writes submitted using the
154 same context.
155
156 This requires kernel 4.0 or newer.
157
158 skip=
159 How many 512-byte sectors of the encrypted data to skip at the
160 beginning. This is different from the offset= option with respect
161 to the sector numbers used in initialization vector (IV)
162 calculation. Using offset= will shift the IV calculation by the
163 same negative amount. Hence, if offset=n is given, sector n will
164 get a sector number of 0 for the IV calculation. Using skip= causes
165 sector n to also be the first sector of the mapped device, but with
166 its number for IV generation being n.
167
168 This option is only relevant for plain devices.
169
170 size=
171 Specifies the key size in bits. See cryptsetup(8) for possible
172 values and the default value of this option.
173
174 sector-size=
175 Specifies the sector size in bytes. See cryptsetup(8) for possible
176 values and the default value of this option.
177
178 swap
179 The encrypted block device will be used as a swap device, and will
180 be formatted accordingly after setting up the encrypted block
181 device, with mkswap(8). This option implies plain.
182
183 WARNING: Using the swap option will destroy the contents of the
184 named partition during every boot, so make sure the underlying
185 block device is specified correctly.
186
187 tcrypt
188 Use TrueCrypt encryption mode. When this mode is used, the
189 following options are ignored since they are provided by the
190 TrueCrypt header on the device or do not apply: cipher=, hash=,
191 keyfile-offset=, keyfile-size=, size=.
192
193 When this mode is used, the passphrase is read from the key file
194 given in the third field. Only the first line of this file is read,
195 excluding the new line character.
196
197 Note that the TrueCrypt format uses both passphrase and key files
198 to derive a password for the volume. Therefore, the passphrase and
199 all key files need to be provided. Use tcrypt-keyfile= to provide
200 the absolute path to all key files. When using an empty passphrase
201 in combination with one or more key files, use "/dev/null" as the
202 password file in the third field.
203
204 tcrypt-hidden
205 Use the hidden TrueCrypt volume. This option implies tcrypt.
206
207 This will map the hidden volume that is inside of the volume
208 provided in the second field. Please note that there is no
209 protection for the hidden volume if the outer volume is mounted
210 instead. See cryptsetup(8) for more information on this limitation.
211
212 tcrypt-keyfile=
213 Specifies the absolute path to a key file to use for a TrueCrypt
214 volume. This implies tcrypt and can be used more than once to
215 provide several key files.
216
217 See the entry for tcrypt on the behavior of the passphrase and key
218 files when using TrueCrypt encryption mode.
219
220 tcrypt-system
221 Use TrueCrypt in system encryption mode. This option implies
222 tcrypt.
223
224 tcrypt-veracrypt
225 Check for a VeraCrypt volume. VeraCrypt is a fork of TrueCrypt that
226 is mostly compatible, but uses different, stronger key derivation
227 algorithms that cannot be detected without this flag. Enabling this
228 option could substantially slow down unlocking, because VeraCrypt's
229 key derivation takes much longer than TrueCrypt's. This option
230 implies tcrypt.
231
232 timeout=
233 Specifies the timeout for querying for a password. If no unit is
234 specified, seconds is used. Supported units are s, ms, us, min, h,
235 d. A timeout of 0 waits indefinitely (which is the default).
236
237 tmp
238 The encrypted block device will be prepared for using it as /tmp;
239 it will be formatted using mke2fs(8). This option implies plain.
240
241 WARNING: Using the tmp option will destroy the contents of the
242 named partition during every boot, so make sure the underlying
243 block device is specified correctly.
244
245 tries=
246 Specifies the maximum number of times the user is queried for a
247 password. The default is 3. If set to 0, the user is queried for a
248 password indefinitely.
249
250 verify
251 If the encryption password is read from console, it has to be
252 entered twice to prevent typos.
253
254 pkcs11-uri=
255 Takes a RFC7512 PKCS#11 URI[1] pointing to a private RSA key which
256 is used to decrypt the key specified in the third column of the
257 line. This is useful for unlocking encrypted volumes through
258 security tokens or smartcards. See below for an example how to set
259 up this mechanism for unlocking a LUKS volume with a YubiKey
260 security token. The specified URI can refer directly to a private
261 RSA key stored on a token or alternatively just to a slot or token,
262 in which case a search for a suitable private RSA key will be
263 performed. In this case if multiple suitable objects are found the
264 token is refused. The key configured in the third column is passed
265 as is to RSA decryption. The resulting decrypted key is then base64
266 encoded before it is used to unlock the LUKS volume.
267
268 x-systemd.device-timeout=
269 Specifies how long systemd should wait for a device to show up
270 before giving up on the entry. The argument is a time in seconds or
271 explicitly specified units of "s", "min", "h", "ms".
272
273 x-initrd.attach
274 Setup this encrypted block device in the initramfs, similarly to
275 systemd.mount(5) units marked with x-initrd.mount.
276
277 Although it's not necessary to mark the mount entry for the root
278 file system with x-initrd.mount, x-initrd.attach is still
279 recommended with the encrypted block device containing the root
280 file system as otherwise systemd will attempt to detach the device
281 during the regular system shutdown while it's still in use. With
282 this option the device will still be detached but later after the
283 root file system is unmounted.
284
285 All other encrypted block devices that contain file systems mounted
286 in the initramfs should use this option.
287
288 At early boot and when the system manager configuration is reloaded,
289 this file is translated into native systemd units by systemd-
290 cryptsetup-generator(8).
291
293 Example 1. /etc/crypttab example
294
295 Set up four encrypted block devices. One using LUKS for normal storage,
296 another one for usage as a swap device and two TrueCrypt volumes.
297
298 luks UUID=2505567a-9e27-4efe-a4d5-15ad146c258b
299 swap /dev/sda7 /dev/urandom swap
300 truecrypt /dev/sda2 /etc/container_password tcrypt
301 hidden /mnt/tc_hidden /dev/null tcrypt-hidden,tcrypt-keyfile=/etc/keyfile
302 external /dev/sda3 keyfile:LABEL=keydev keyfile-timeout=10s
303
304 Example 2. Yubikey-based Volume Unlocking Example
305
306 The PKCS#11 logic allows hooking up any compatible security token that
307 is capable of storing RSA decryption keys. Here's an example how to set
308 up a Yubikey security token for this purpose, using ykman from the
309 yubikey-manager project:
310
311 # Make sure noone can read the files we generate but us
312 umask 077
313
314 # Destroy any old key on the Yubikey (careful!)
315 ykman piv reset
316
317 # Generate a new private/public key pair on the device, store the public key in 'pubkey.pem'.
318 ykman piv generate-key -a RSA2048 9d pubkey.pem
319
320 # Create a self-signed certificate from this public key, and store it on the
321 # device. The "subject" should be an arbitrary string to identify the token in
322 # the p11tool output below.
323 ykman piv generate-certificate --subject "Knobelei" 9d pubkey.pem
324
325 # Check if the newly create key on the Yubikey shows up as token in PKCS#11. Have a look at the output, and
326 # copy the resulting token URI to the clipboard.
327 p11tool --list-tokens
328
329 # Generate a (secret) random key to use as LUKS decryption key.
330 dd if=/dev/urandom of=plaintext.bin bs=128 count=1
331
332 # Encode the secret key also as base64 text (with all whitespace removed)
333 base64 < plaintext.bin | tr -d '\n\r\t ' > plaintext.base64
334
335 # Encrypt this newly generated (binary) LUKS decryption key using the public key whose private key is on the
336 # Yubikey, store the result in /etc/encrypted-luks-key.bin, where we'll look for it during boot.
337 sudo openssl rsautl -encrypt -pubin -inkey pubkey.pem -in plaintext.bin -out /etc/encrypted-luks-key.bin
338
339 # Configure the LUKS decryption key on the LUKS device. We use very low pbkdf settings since the key already
340 # has quite a high quality (it comes directly from /dev/urandom after all), and thus we don't need to do much
341 # key derivation. Replace /dev/sdXn by the partition to use (e.g. sda1)
342 sudo cryptsetup luksAddKey /dev/sdXn plaintext.base64 --pbkdf=pbkdf2 --pbkdf-force-iterations=1000
343
344 # Now securely delete the plain text LUKS key, we don't need it anymore, and since it contains secret key
345 # material it should be removed from disk thoroughly.
346 shred -u plaintext.bin plaintext.base64
347
348 # We don't need the public key anymore either, let's remove it too. Since this one is not security
349 # sensitive we just do a regular "rm" here.
350 rm pubkey.pem
351
352 # Test: Let's run systemd-cryptsetup to test if this all worked. The option string should contain the full
353 # PKCS#11 URI we have in the clipboard, it tells the tool how to decypher the encrypted LUKS key.
354 sudo systemd-cryptsetup attach mytest /dev/sdXn /etc/encrypted-luks-key.bin 'pkcs11-uri=pkcs11:...'
355
356 # If that worked, let's now add the same line persistently to /etc/crypttab, for the future.
357 sudo bash -c 'echo "mytest /dev/sdXn /etc/encrypted-luks-key \'pkcs11-uri=pkcs11:...\'" >> /etc/crypttab'
358
359 A few notes on the above:
360
361 · We use RSA (and not ECC), since Yubikeys support PKCS#11 Decrypt()
362 only for RSA keys
363
364 · We use RSA2048, which is the longest key size current Yubikeys
365 support
366
367 · LUKS key size must be shorter than 2048bit due to RSA padding,
368 hence we use 128 bytes
369
370 · We use Yubikey key slot 9d, since that's apparently the keyslot to
371 use for decryption purposes, see documentation[2].
372
374 systemd(1), systemd-cryptsetup@.service(8), systemd-cryptsetup-
375 generator(8), fstab(5), cryptsetup(8), mkswap(8), mke2fs(8)
376
378 1. RFC7512 PKCS#11 URI
379 https://tools.ietf.org/html/rfc7512
380
381 2. see documentation
382 https://developers.yubico.com/PIV/Introduction/Certificate_slots.html
383
384
385
386systemd 245 CRYPTTAB(5)