nixos-yubikey-luks icon indicating copy to clipboard operation
nixos-yubikey-luks copied to clipboard

How to add a backup key?

Open Janik-Haag opened this issue 2 years ago • 5 comments

Can you add a section explaining how one would add a second yubikey as a backup device?

Janik-Haag avatar Jul 08 '23 12:07 Janik-Haag

Wondering this as well. I'm taking a look at the options available under boot.initrd.luks.devices.*.yubikey and it really just seems like only a single yubikey is supported, unfortunately.

ElnuDev avatar Sep 22 '23 00:09 ElnuDev

Can you advise how to add at least a backup passphrase, for when your yubikey is lost?

Deep-Six avatar May 03 '24 08:05 Deep-Six

Yeah, sorry, I think I can probably come up with something.

sgillespie avatar May 03 '24 13:05 sgillespie

Sorry @sgillespie I managed to find something in the official NixOS docs, this worked for me.

 # Be sure to delete luks.key afterwards
KEY_LENGTH=512
ITERATIONS=1000000
read -s k_user
challenge=$(head -n1 /boot/crypt-storage/default | tr -d '\n' | openssl dgst -binary -sha512 | rbtohex)
response="$(ykchalresp -2 -x $challenge 2>/dev/null)"
echo -n $k_user | pbkdf2-sha512 $(($KEY_LENGTH / 8)) $ITERATIONS $response > luks.key
# Now, you can pass the luks.key to any cryptsetup command. For instance,
# if you want to add another key to your setup.
cryptsetup luksAddKey /dev/nvme0n1p2 luks.key
rm luks.key

Deep-Six avatar May 03 '24 14:05 Deep-Six

@Deep-Six That's awesome! Feel free to add that to the README somewhere

sgillespie avatar May 03 '24 16:05 sgillespie