在Debian系统中,可通过以下工具实现文件系统加密与解密,以下是具体方法及对应命令:
适用场景:加密整个磁盘或分区,支持透明加密。
工具:cryptsetup(基于LUKS标准)
步骤:
安装工具
sudo apt update && sudo apt install cryptsetup
加密分区
sudo cryptsetup luksFormat /dev/sdX # 替换为实际分区(如/dev/sda1)
sudo cryptsetup luksOpen /dev/sdX encrypted_partition # 创建映射名称
sudo mkfs.ext4 /dev/mapper/encrypted_partition # 格式化
sudo mount /dev/mapper/encrypted_partition /mnt # 挂载到指定目录
解密与卸载
sudo umount /mnt # 卸载挂载点
sudo cryptsetup luksClose encrypted_partition # 关闭加密映射
自动挂载(可选)
编辑 /etc/crypttab 和 /etc/fstab,添加加密卷信息以实现开机自动挂载。
适用场景:加密单个文件或目录,支持对称/非对称加密。
工具:gpg
步骤:
安装工具
sudo apt install gnupg
加密文件
gpg --output encrypted_file.gpg --encrypt --recipient "your_email@example.com" file_to_encrypt
# 或对称加密(直接输入密码):
gpg --output encrypted_file.gpg --symmetric --cipher-algo AES256 file_to_encrypt
解密文件
gpg --output decrypted_file --decrypt encrypted_file.gpg
# 输入密码(若为对称加密)
加密目录
先用 tar 打包目录,再用GPG加密:
tar czf - directory_to_encrypt | gpg --output encrypted_dir.tar.gz.gpg --encrypt --recipient "your_email@example.com"
适用场景:创建加密的虚拟磁盘文件,支持跨平台。
工具:veracrypt
步骤:
安装工具
sudo apt install veracrypt
创建加密卷
veracrypt --create /path/to/encrypted_volume --size 1G --encryption AES --hash SHA-512 --password your_password
挂载/卸载加密卷
veracrypt /path/to/encrypted_volume /mnt/encrypted --password your_password # 挂载
veracrypt -d /mnt/encrypted # 卸载
sudo)。根据需求选择合适工具:LUKS适合磁盘级加密,GnuPG适合文件级加密,VeraCrypt适合跨平台虚拟加密。[1,2,3,4,5,6,7,9,10,11]