r/linuxadmin • u/Aim_Fire_Ready • Nov 18 '25
How to securely auto-decrypt LUKS on boot up
I have a personal machine running Linux Mint that I'm using to learn more about Linux administration. It's a fresh install with LVM + LUKS. My main issue with this is that I have to manually decrypt the drive every time it boots up. An online search and a weird chat with AI did not show any obvious solution. Suggestions included:
- storing the keyfile on a non-encrypted part of the drive, but that negates the benefits
- storing the keyfile on a USB drive, but that negates the benefits too
- storing the keyfile in TPM, but this failed (probably a PEBKAC, though)
Ideally, I'd like to get it to function like Bitlocker in that the key is not readable without some authentication and no separate hardware is required. Please advise.
19
Upvotes
8
u/Anticept Nov 18 '25
There's a post here about using the TPM to do it. It's not specific to mint, but maybe it will still help? https://www.reddit.com/r/Fedora/comments/szlvwd/psa_if_you_have_a_luks_encrypted_system_and_a/
24
u/d00ber Nov 18 '25
I use clevis and tang, but I'm a weirdo. That way when I'm at home I never have to enter it, but if I'm out I have to enter it every time.
5
u/arrozconplatano Nov 18 '25
TPM is your best bet. I didn't have any problems setting it up with systemd-cryptenroll
2
u/xagarth Nov 19 '25
No such thing as secure AUTO-DECRYPT.
What's the point of encrypting this if it can be decrypted by simply turning it on?
2
u/UltraChip Nov 21 '25
People have already mentioned using TPM via systemd-cryptenroll so I'll just say that's the method I've been using and it's been working great.
3
u/Le_Vagabond Nov 19 '25
yubikey on boot, fall back to encryption password.
2
u/DarkwolfAU Nov 18 '25
TPM worked fine for me, but your mileage may vary and you can’t use any third party at-boot kernel modules.
I did this for a laptop with Ubuntu.
2
u/hadrabap Nov 19 '25
I use TPM2 on my main machine. The machine then provides a Tang server for my laptop. When the laptop is connected to my network using Ethernet cable and my main machine is up, the laptop unlocks itself. Otherwise, it asks for a password.
Something similar goes with the main machine. When something changes, hardware or software wise, the unlocking fails, and I'm prompted for a password. The main machine is a data center grade stuff so I can use remote feature of BMC/IPMI to provide the password remotely.
RHEL 10 (and clones) support unlocking with a smart card such as YubiKey PIV, but I've not been much successful with it. The issue is that the feature depends on OpenSC whereas I use pcscd with
libykcs11.soPKCS driver and these two solutions are incompatible. LOLBy the way, the TPM2 unlocking doesn't work by storing a key in the TPM. It works by encrypting the real key with certain RC hashes provided by the TPM and storing the encrypted stuff in the LUKS header. There are 16 RC registers and each of them is managed by a different component that is part of the boot process, like UEFI/BIOS configuration checksum, HW configuration checksum, intrusion detection checksum, systemd has one, Linux kernel another one, grub… Fresh hashes are obtained on each boot and the real key is tried to be decrypted with the hashes. If it fails, the boot process asks for a password, or tries another method.
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/security_hardening/configuring-automated-unlocking-of-encrypted-volumes-using-policy-based-decryption_security-hardening#basic-nbde-and-tpm2-encryption-client-operations_configuring-automated-unlocking-of-encrypted-volumes-using-policy-based-decryption
https://uapi-group.org/specifications/specs/linux_tpm_pcr_registry/
Give it a try!
2
u/linxbro5000 Nov 20 '25
Not a 100% perfect idea: have a look at something like https://github.com/vnightsong/initramfs-zerotier
"I created this for my own purposes and to solve a specific problem: I use root encryption for my home lab. I use dropbear ssh in initramfs to remotely unlock my machines. If a machine goes offline while I am out of the house, I want to be able to unlock it so it can finish booting after a restart or something. This allows me to ssh into any machine regardless where I am or what networks I'm on."
The idea of on "unlock by (remote) SSH" can be scripted, right?
1
u/Known_Experience_794 Nov 19 '25
This is a problem I’ve been trying to solve as well. But my use case is a bit different. I am setting up a Linux computer at a family member’s house. It’s for if my house burns down kind of thing. It will be running syncthing and I will remote into it from time to time. But, since it will reside outside of my home, it needs to have Full Disk Encryption as some of the data on it will be sensitive.
Normally in the Windows world, I use Bitlocker with a pre-boot pin. This prevents someone from accessing the data directly on the drive or by stealing the entire laptop. But it requires my presence on boot to enter the preboot pin.
But in this case, I won’t be anywhere near the system when it boots. So I’m trying to figure out a way to have my cake and eat it too with this one. 😅
1
u/zoredache Nov 19 '25
You could do something like get an Ironkey. Basically a USB stick that has full disk encryption, and you unlock by entering a pin on the USB stick. You can set a timeout on the USB stick so that it auto-locks after 5-20 minutes or something like that.
1
u/michaelpaoli Nov 19 '25
So ... how do you want to securely auto-decrypt? Password/phassphrase has to come from somewhere/something/someone, so, how do you want to do that. And if it's (far too) easy and on the same host itself, that typically wouldn't be secure, as then essentially anyone could do it - just steal the computer, boot it and ... access - or at least pretty close to that or generally much easier to gain access from there (e.g. tap the hardware and read the private keys from RAM).
There are also potential ways to do it with, e.g. hardware token, or that + some biometrics ... or using something(s) local on the network or in the environment, that couldn't be easily subverted if, e.g. the laptop were moved or taken elsewhere.
1
u/clvx Nov 19 '25
TPM + secure boot. Add a yubikey or something else to tpm if you feel like it needs to be protected when you are not around. I just did this in a root btrfs encrypted + a raid 10 btrfs + 2 encrypted swaps. I was absolutely going nuts with every single decryption.
1
u/yarmak Nov 20 '25
I used to maintain my own secure boot solution to make sure loader is not tampered on the unlock stage. But there is a project which went farther and uses TPM for it: https://github.com/noahbliss/mortar
Probably this is the state of art solution.
1
u/BorderCollie4Life Feb 19 '26
My problem is similar and I think it is perfectly possible to auto-unlock in a secure way without hardware.
My setup is a first SSD with the OS (Tuxedo/Kubuntu) with LVM/LUKS. It asks for my ancryption password to boot. All fine. Now I added a second 4TB SSD for data only which I also want to encrypt, but I don't want to enter a second password (or the same a second time if I don't want two different ones).
For me, it would be ideal to just have to enter the password for the system drive, but have the second drive unlocked automatically before I log in (so I can have my home folder on the second SSD). This should be possible with the password/key/whatever to unlock the second drive stored on the also encrypted system disk, where it would be well protected.
I just haven't found a way to do that yet ...
1
u/Academic-Gate-5535 Nov 19 '25 edited Nov 19 '25
That's the problem, it's not secure if people can just decrypt it,even with TPM
1
u/Sirius_Sec_ Nov 19 '25
Why would you encrypt something just to have it auto decrypt ? The whole point is you need a password to view its contents . If you want just encrypt whatever files or directories you want and decrypt after boot .
0
u/sogun123 Nov 20 '25
Depends what is your use case. One option is not to encrypt root and decrypt your home by your password - either via pam plugin or via systemd homed. Tpm encryption makes sense if you care only about stolen hard drive, without the pc.
0
u/[deleted] Nov 18 '25
[deleted] — view deleted comment
0
u/[deleted] Nov 18 '25
[deleted] — view deleted comment
0
u/[deleted] Nov 18 '25
[deleted] — view deleted comment
6
u/[deleted] Nov 18 '25
[removed] — view removed comment