Learn how to test LUKS passphrase on a specific device.
Quickly test correct passphrase.
Exit code indicates that this passphrase can be used to access this device.
$ printf "anycurrentpassphrase" | sudo cryptsetup luksOpen --test-passphrase /dev/sdc1 && echo "There is a key available with this passphrase."
There is a key available with this passphrase.
Quickly test incorrect passphrase.
$ printf "anyincorrectpassphrase" | sudo cryptsetup luksOpen --test-passphrase /dev/sdc1 && echo "There is a key available with this passphrase."
No key available with this passphrase.
Test a passphrase stored in a file or a binary key.
Remember that passphrase stored in a file cannot contain new-line character.
$ sudo cryptsetup luksOpen --key-file backup_key --test-passphrase /dev/sdc1 && echo "There is a key available with this passphrase." || echo "No key available with this passphrase."
There is a key available with this passphrase.
Test a passphrase stored in a file in a specific key-slot.
$ sudo cryptsetup luksOpen --key-file backup_key --test-passphrase --key-slot 6 /dev/sdc1 && echo "There is a key available with this passphrase." || echo "No key available with this passphrase."
No key available with this passphrase.
$ sudo cryptsetup luksOpen --key-file backup_key --test-passphrase --key-slot 7 /dev/sdc1 && echo "There is a key available with this passphrase." || echo "No key available with this passphrase."
There is a key available with this passphrase.