最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Debian挂载加密卷方法
时间:2026-07-19 07:18:50 编辑:袖梨 来源:一聚教程网
Installing Required ToolsBefore mounting an encrypted volume, ensure the cryptsetup utility is installed—it’s essential for managing LUKS (Linux Unified Key Setup) encrypted partitions. Run:
sudo apt update && sudo apt install cryptsetupThis command installs the necessary tools to handle encryption and decryption tasks.
Identifying the Encrypted PartitionUse lsblk or fdisk -l to list all storage devices and partitions. Locate the encrypted partition (e.g., /dev/sdb1)—this is the device you’ll work with. For example:
lsblkOutput might show /dev/sdb1 as a partition of type crypto_LUKS.
Opening the Encrypted PartitionTo access the encrypted data, you need to “open” the partition using cryptsetup luksOpen. This command maps the encrypted device to a virtual device under /dev/mapper/. Replace /dev/sdb1 with your partition and my_encrypted_partition with a custom name:
sudo cryptsetup luksOpen /dev/sdb1 my_encrypted_partitionYou’ll be prompted to enter the encryption password you set during the LUKS formatting step. After successful authentication, the mapped device (/dev/mapper/my_encrypted_partition) will appear.
Formatting the Encrypted Partition (If Needed)If the encrypted partition is new, you must format it with a file system (e.g., ext4). Use mkfs.ext4 (or another file system of your choice) on the mapped device:
sudo mkfs.ext4 /dev/mapper/my_encrypted_partitionThis step prepares the partition for storing data.
Mounting the Decrypted PartitionCreate a directory to serve as the mount point (e.g., /mnt/encrypted_data) and mount the decrypted device:
sudo mkdir -p /mnt/encrypted_datasudo mount /dev/mapper/my_encrypted_partition /mnt/encrypted_dataThe encrypted partition is now accessible via the mount point. You can verify this with ls /mnt/encrypted_data.
Closing the Encrypted PartitionWhen you’re done using the encrypted volume, unmount it and close the encrypted mapping to secure the data:
sudo umount /mnt/encrypted_datasudo cryptsetup luksClose my_encrypted_partitionThe mapped device (/dev/mapper/my_encrypted_partition) will disappear, and the partition will be locked again.
Setting Up Automatic Mounting at BootTo avoid manually opening and mounting the encrypted partition each time the system starts, add entries to /etc/crypttab (for unlocking) and /etc/fstab (for mounting).
Edit
/etc/crypttab: Add a line specifying the mapped name, device path, and key file (usenoneif no key file is used):my_encrypted_partition /dev/sdb1 none luksThis tells the system to unlock the partition at boot.
Edit
/etc/fstab: Add a line to mount the decrypted device to your desired directory. Use the mapped device (/dev/mapper/my_encrypted_partition) and your file system type:/dev/mapper/my_encrypted_partition /mnt/encrypted_data ext4 defaults 0 2The
defaultsoption enables standard mounting behavior, and0 2sets the dump and fsck priorities.
Important Tips for Security & Maintenance
- Use Strong Passwords: Choose a complex password with uppercase/lowercase letters, numbers, and special characters. Avoid common words or easily guessable phrases.
- Backup Encryption Headers: LUKS stores critical encryption metadata (like the master key) in the partition header. If this header is damaged, your data may be unrecoverable. Regularly back up the header using:
Store the backup securely (e.g., on an external drive or cloud storage with encryption).sudo cryptsetup luksHeaderBackup /dev/sdb1 --header-backup-file /path/to/backup.img - Avoid Storing Passwords in Plaintext: Never add your encryption password to
/etc/fstabor scripts. Instead, rely on the system’s keyring or manual input for security. - Test Automatic Mounting: After configuring
/etc/crypttaband/etc/fstab, reboot your system to ensure the encrypted partition unlocks and mounts correctly. Verify withlsblkordf -hthat the partition appears under the correct mount point.
相关文章
- 检疫区最后一站结膜炎与红眼区别一览 07-21
- 超大杯研究员的异常求汁欲第二章流程及单词出处 07-21
- 斗罗大陆诛邪传说什么时候上线 07-21
- 原神八重神子选精通沙还是攻击沙好 07-21
- 我不是盐神网站入口在哪 07-21
- 冒险者旅馆2全流程通关攻略是什么 07-21