使用LUKS加密Linux分区

安装和卸载

首先,要手动安装加密分区,请运行以下命令。

# cryptsetup --type luks open /dev/sdb1 encrypted
# mount -t ext4 /dev/mapper/encrypted /place/to/mount

卸下分区与普通分区相同,但我们必须关闭映射设备。

# umount /place/to/mount
# cryptsetup close encrypted

设置分区

警告:以下将删除正在使用的分区上的所有数据,并将使其无法恢复。

基本选项如下:

--cypher:  This determines the cryptographic cypher used on the partition.  The default option is aes-xts-plain64
--key-size: The length of the key used.  The default is 256
--hash: Chooses the hash algorithm used to derive the key.  The default is sha256.
--time: The time used for passphrase processing.  The default is 2000 milliseconds.
--use-random/--use-urandom: Determines the random number generator used.  The default is --use-random.

因此,没有选项的基本命令看起来像下面的行。

# cryptsetup luksFormat /dev/sdb1

显然,我们希望使用我们加密的任何分区的路径。
指定选项后,它将看起来如下。

# cryptsetup -c aes-xts-plain64 --key-size 512 --hash sha512 --time 5000 --use-urandom /dev/sdb1

cryptsetup将要求密码。
如果我们忘记密码,数据将会丢失。

完成后,它将成功将分区转换为加密的LUKS卷。
接下来,我们必须将卷打开到设备映射器上。

# cryptsetup open /dev/sdb1 encrypted

映射驱动器后,我们必须为分区选择文件系统类型。
创建文件系统与普通分区相同。

# mkfs.ext4 /dev/mapper/encrypted

安装cryptsetup

debian/ubuntu

$sudo apt-get install cryptsetup

Centos/Fedora

Centos

# yum install crypto-utils cryptsetup-luks cryptsetup-luks-devel cryptsetup-luks-libs

Fedora

# dnf install crypto-utils cryptsetup cryptsetup-luks

opensuse

# zypper in cryptsetup

Arch Linux.

# pacman -S cryptsetup

Gentoo

# emerge --ask cryptsetup
日期:2020-07-07 20:56:00 来源:oir作者:oir