Encryption not only protects data from unauthorized access if the disk is stolen but also ensures that sensitive information remains safe even in environments with high-security requirements.
- Plain mode
- LUKS (Linux Unified Key Setup)
Setting Up Plain Mode Encryption
Suppose you want to encrypt the device/dev/vde using plain mode. Run the following command to open the device with password verification. The flag --verify-passphrase prompts you to enter the password twice, which helps to avoid typing errors that might lead to data corruption:
openinstructs Cryptsetup to prepare the device for encrypted read and write operations.--type plainspecifies the plain encryption mode./dev/vderepresents the physical device to be encrypted.mysecuredisknames the mapped device, which becomes accessible as/dev/mapper/mysecuredisk.
mkfs.xfs, the Linux kernel automatically encrypts it before saving it to the physical device. Similarly, data is decrypted on the fly when reading from /dev/mapper/mysecuredisk.
Always unmount and close the mapped device when it is not in use. Failing to do so may expose the encrypted data to unauthorized access.
/dev/vde remains fully encrypted and inaccessible without the proper credentials.
Configuring LUKS Encryption
LUKS is generally preferred over plain mode due to its additional features, such as efficient key management and header metadata support. To format a disk or partition with LUKS encryption, use the following command. Note that you must capitalize the “F” inluksFormat:
--verify-passphrase.
To change the encryption key on a LUKS-encrypted device later, run:
Encrypting a Specific Partition
In some cases, you might want to encrypt only a specific partition rather than an entire disk. For instance, a system could boot from an unencrypted partition (e.g.,/dev/vde1), while a second partition (/dev/vde2) is encrypted to protect personal data. The process remains the same—simply target the desired partition:
For LUKS encryption:
/dev/vde2 accordingly.
Summary
Both plain mode and LUKS encryption methods can effectively secure data on Linux storage devices. LUKS is typically favored due to its enhanced features and ease of key management. This guide has demonstrated how to:- Encrypt storage devices using Cryptsetup.
- Create and manage mapped devices.
- Format, mount, and access encrypted filesystems.
- Safeguard data against unauthorized access, even if the physical disk is compromised.