Debian系统可通过以下工具实现文件加密与解密,以下是具体方法及对应命令:
适用场景:加密单个文件/目录,支持公钥加密(适合安全传输)。
sudo apt update && sudo apt install gnupg
。gpg --full-generate-key
(按提示输入姓名、邮箱等信息)。gpg --encrypt --recipient "收件人邮箱" file.txt
,生成file.txt.gpg
。gpg --decrypt file.txt.gpg
,输入私钥密码后解密。适用场景:对称加密(快速加密大文件)或非对称加密。
sudo apt install openssl
。openssl enc -aes-256-cbc -salt -in file.txt -out file.enc -pass pass:密码
。openssl enc -d -aes-256-cbc -in file.enc -out file.txt -pass pass:密码
。openssl genpkey -algorithm RSA -out private_key.pem
(私钥),openssl rsa -pubout -in private_key.pem -out public_key.pem
(公钥)。openssl rsautl -encrypt -pubin -inkey public_key.pem -in file.txt -out file.enc
。openssl rsautl -decrypt -inkey private_key.pem -in file.enc -out file.txt
。适用场景:透明加密目录(无需手动操作加密/解密)。
sudo apt install ecryptfs-utils
。sudo mount -t ecryptfs ~/plaintext ~/encrypted
(按提示设置加密选项)。sudo umount ~/encrypted
。sudo apt install encfs
。encfs ~/encrypted ~/decrypted
(按提示设置密码)。fusermount -u ~/encrypted
。适用场景:加密整个磁盘或分区(需手动操作)。
sudo apt install cryptsetup
。sudo cryptsetup luksFormat /dev/sdX
(sdX
替换为实际分区)。sudo cryptsetup open /dev/sdX encrypted_partition
。sudo mkfs.ext4 /dev/mapper/encrypted_partition && sudo mount /dev/mapper/encrypted_partition /mnt
。sudo umount /mnt && sudo cryptsetup close encrypted_partition
。适用场景:创建加密容器或虚拟磁盘(跨平台兼容)。
sudo apt install veracrypt
。veracrypt --create /path/to/volume --encryption AES --hash SHA-512 --size 1G
。veracrypt /path/to/volume /mnt/point --password 密码
(挂载),veracrypt -d /mnt/point
(卸载)。注意:
tar
)结合加密命令。