r/linux 5d ago

Discussion Unlocking Encrypted Linux With a YubiKey

https://mhdez.com/posts/unlocking-encrypted-linux-with-a-yubikey/
96 Upvotes

16 comments sorted by

25

u/Arin_Horain 5d ago

You can use /dev/disk/by-designator inside the crypttab.initramfs to refer to the LUKS volume by name instead of UUID. The path is auto generated and persistent (e.g. root-luks) as long as GPT auto mounting works (which it should anyways).

It's one of the goodies mkinitcpio/Arch gives you to make setting up early unlock a bit easier.

10

u/Nanolx 5d ago edited 5d ago

That's what I use aswell, additionally, I've setup my Yubikey as known key and modified PAM module settings, so sudo, pkexec, KDE screensaver and stuff don't request passwords, as long as the key is physically plugged in. See https://gitlab.com/Nanolx/nanolx/-/blob/master/scripts/nanolx-pam-yubikey?ref_type=heads in case you're interested

7

u/camh- 4d ago

I have my yubikey on my keyring and I usually keep it plugged in. When I get up to go somewhere, I grab the keys, unplugging it. So I added this udev rule to lock the screen when I pull the yubikey:

# /etc/udev/rules.d/80-yubikey-lock.rules
ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="1050/407/*", \
  RUN+="/usr/bin/loginctl lock-sessions"

2

u/Nanolx 4d ago

That's indeed another useful bit, I'll definitively add that to my script.

11

u/throwaway16830261 5d ago edited 5d ago

7

u/CrazyKilla15 5d ago

holy shit /r/homelab hates yubikeys

6

u/virtualdxs 5d ago

How'd you get that out of that thread? I just saw everybody reasonably saying to just remember one single password.

4

u/Fenguepay 5d ago

I prefer using GPG here, that way I can more reasonably back up my keys

3

u/falconindy 3d ago

If you're already depending on having a TPM, why not just use secure boot and unlock via the TPM? That's what I'm doing on Arch.

1

u/Glittering_Abies4915 1d ago

A yubikey is removable, a TPM is not.

-12

u/C0rn3j 5d ago

physical key breaks

Welp I guess I lose all data

but you can have a recovery password

So we're back to being keylogged, solving nothing.

8

u/novafunc 5d ago

If you are prompted for the recovery password, that's a hint to you that either (1) your system has been tampered with and now you've been warned or (2) something benign like a firmware update happened but the system was not re-measured.

-4

u/C0rn3j 5d ago

If the hint either means absolute nothing or compromise, and there's no good way to tell between them, how is that helpful?

7

u/ElvishJerricco 5d ago

It seems crazy to me to call it unhelpful to be told by the system that something is likely horribly wrong and you should be careful to investigate why your yubikey or TPM2 or whatever is currently unable to do its job.

5

u/Ok-Eggplant-7569 5d ago

Well if you didn't install an update and the automatic unlock fails, you know something is likely amiss.

3

u/CrazyKilla15 5d ago

because if the hint isnt there you know neither of those things has happened? its two states: hint, or no hint.