A robust bash script that configures automatic LUKS decryption using TPM2 and Clevis for Ubuntu/Debian systems. This script eliminates the need to manually enter disk encryption passwords at boot time while maintaining security through TPM2 hardware security module.
Bryan Kemp
Licensed under the BSD 3-Clause License
- Automatic LUKS partition detection: Intelligently detects encrypted partitions using multiple methods
- TPM2 integration: Leverages TPM2 hardware security module for secure key storage
- PCR binding: Supports PCR 7 binding for enhanced security (boot state verification)
- Flexible hash algorithms: Supports both SHA256 and SHA1 hash algorithms
- Robust error handling: Comprehensive error checking and recovery mechanisms
- Verbose logging: Optional detailed logging for troubleshooting
- Safe operations: Validates existing bindings before making changes
- Initramfs integration: Automatically configures initramfs hooks for boot-time decryption
- TPM2 chip (TPM 2.0) enabled in BIOS/UEFI
- LUKS-encrypted partition (typically root filesystem)
- Ubuntu 20.04+ or Debian 11+ (systemd-based systems)
- Bash 4.0+
- sudo privileges
- Internet connection for package installation
- TPM2 must be enabled in BIOS/UEFI settings
- Secure Boot recommended but not required
- Physical security of the machine is important (TPM2 protects against software attacks, not physical theft)
- Backup your LUKS keys before running this script
-
Clone or download the script:
git clone <repository-url> cd autodecrypt
-
Make the script executable:
chmod +x autodecrypt.sh
-
Run the installation:
./autodecrypt.sh install
# Install dependencies and configure auto-decryption
./autodecrypt.sh install
# Test current auto-decryption setup
./autodecrypt.sh test
# Remove auto-decryption configuration
./autodecrypt.sh uninstall
# Show help
./autodecrypt.sh --help# Enable verbose logging
./autodecrypt.sh --verbose install
# Verbose testing
./autodecrypt.sh -v testThe script uses Clevis with TPM2 backend to:
- Detect LUKS partitions using multiple detection methods
- Verify TPM2 availability and functionality
- Create TPM2 bindings with optional PCR (Platform Configuration Register) binding
- Update initramfs to include Clevis hooks for boot-time decryption
- Test the configuration to ensure it works properly
- TPM2 stores encryption keys sealed to the current system state
- PCR 7 binding (when available) ensures keys are only released when boot state is unchanged
- Fallback mechanisms provide compatibility with various TPM2 configurations
- Existing passphrases remain valid as backup authentication methods
The script uses three methods to detect LUKS partitions:
- Filesystem type detection: Uses
lsblkto find crypto_LUKS filesystems - Mapped device detection: Finds currently mounted encrypted devices
- Direct cryptsetup verification: Tests each block device with
cryptsetup isLuks
The script automatically detects and configures:
- Hash algorithms: Prefers SHA256, falls back to SHA1
- PCR binding: Attempts PCR 7 binding for enhanced security
- Fallback options: Multiple configuration attempts for maximum compatibility
Clevis bindings are created with these priority levels:
- PCR 7 + SHA256: Most secure option
- PCR 7 + SHA1: Fallback for older systems
- SHA256 only: Compatible but less secure
- SHA1 only: Maximum compatibility
- Default settings: Last resort configuration
"No LUKS partition detected"
- Ensure you have an encrypted partition
- Run with
-vflag to see detection attempts - Manually verify with
sudo cryptsetup luksDump /dev/sdXY
"TPM2 chip not available"
- Enable TPM2 in BIOS/UEFI settings
- Verify with
sudo tpm2_getrandom --hex 16 - Check if TPM2 is accessible:
ls -la /dev/tpm*
"Clevis unlock test failed"
- Verify TPM2 is functioning properly
- Check if PCR values have changed (after BIOS updates)
- Run
sudo clevis luks list -d /dev/sdXYto see existing bindings
"Still prompted for password at boot"
- Ensure initramfs was updated successfully
- Reboot and check for error messages
- Verify Clevis hooks:
lsinitramfs /boot/initrd.img-$(uname -r) | grep clevis
Use the -v or --verbose flag to enable detailed logging:
./autodecrypt.sh --verbose testThis provides additional information about:
- LUKS partition detection attempts
- TPM2 interaction details
- Clevis binding creation process
- Initramfs hook verification
Test your configuration manually:
# List current bindings
sudo clevis luks list -d /dev/sdXY
# Test unlock (replace sdXY with your partition)
sudo clevis luks unlock -d /dev/sdXY -n test_unlock
# Clean up test
sudo cryptsetup luksClose test_unlock- Eliminates manual password entry at boot time
- Maintains encryption security through TPM2 hardware
- Detects system tampering (when using PCR binding)
- Preserves existing authentication methods as backup
- Physical security is crucial - TPM2 doesn't protect against physical attacks
- BIOS/UEFI updates may require reconfiguration due to PCR changes
- TPM2 failure would require manual password entry
- Backup recovery methods should be tested and documented
- Keep existing LUKS passphrases as backup
- Test recovery procedures before relying on auto-decryption
- Monitor system for TPM2 health and functionality
- Document configuration for recovery purposes
- Consider additional security layers like Secure Boot
- Boot normally and enter your LUKS passphrase manually
- Check TPM2 status:
sudo tpm2_getrandom --hex 16 - Test existing bindings:
./autodecrypt.sh test - Reconfigure if needed:
./autodecrypt.sh install
# Remove all Clevis bindings
./autodecrypt.sh uninstall
# Optional: Remove packages (if not needed for other purposes)
sudo apt remove clevis clevis-luks clevis-tpm2 clevis-initramfsThe script automatically installs these packages:
clevis: Core Clevis frameworkclevis-luks: LUKS integration for Clevisclevis-tpm2: TPM2 backend for Clevistpm2-tools: TPM2 utilitiesclevis-initramfs: Initramfs hooks for boot-time decryption
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the BSD 3-Clause License. See the license header in the script for full details.
- Initial release
- Multi-method LUKS detection
- TPM2 integration with PCR binding
- Comprehensive error handling
- Verbose logging support
- Automatic initramfs configuration
For issues and questions:
- Check the troubleshooting section
- Run with verbose mode for detailed logs
- Review system logs:
journalctl -u systemd-cryptsetup@* - Test TPM2 functionality independently
- Clevis project for the TPM2 integration framework
- tpm2-tools for TPM2 utilities
- Ubuntu/Debian communities for cryptsetup and initramfs integration