In ubuntu 19.10 I followed the example here.
The keyfile is at the root of usb key filesystem. usbkey has uuid yyyy.
the /etc/crypttab is like this:
encrypted UUID=xxxx /keyfile:UUID=yyyy luks,keyfile-timeout=60,x-systemd.device-timeout=2min
The automatically generated generator is /run/systemd/generator/[email protected]
# Automatically generated by systemd-cryptsetup-generator
[Unit]
Description=Cryptography Setup for %I
Documentation=man:crypttab(5) man:systemd-cryptsetup-generator(8) man:[email protected](8)
SourcePath=/etc/crypttab
DefaultDependencies=no
Conflicts=umount.target
IgnoreOnIsolate=true
After=cryptsetup-pre.target
Before=cryptsetup.target
RequiresMountsFor=/keyfile:UUID=yyyy
BindsTo=dev-disk-by\x2duuid-xxxx.device
After=dev-disk-by\x2duuid-xxxx.device
Before=umount.target
[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutSec=0
KeyringMode=shared
OOMScoreAdjust=500
ExecStart=/lib/systemd/systemd-cryptsetup attach 'encrypted' '/dev/disk/by-uuid/xxxx' '/keyfile:UUID=yyyy' 'luks,keyfile-timeout=60'
ExecStop=/lib/systemd/systemd-cryptsetup detach 'encrypted'
however, I did not see any thing related to mount the usb key in the journalctl. I always directly launch the system-cryptsetup and fail to find the file.
systemd-cryptsetup[1132]: Encountered unknown /etc/crypttab option 'keyfile-timeout=60', ignoring.
systemd-cryptsetup[1132]: WARNING: Locking directory /run/cryptsetup is missing!
systemd[1]: Started File System Check Daemon to report status.
systemd-cryptsetup[1132]: Set cipher aes, mode xts-plain64, key size 512 bits for device /dev/disk/by-uuid/xxxx
systemd-cryptsetup[1132]: Failed to open key file.
systemd-cryptsetup[1132]: Failed to activate with key file '/keyfile:UUID=yyyy