Linux下的磁盘加密LUKS

LUKS(Linux Unified Key Setup)为Linux硬盘分区加密提供了一种标准,它不仅能通用于不同的Linux发行版本,还支持多用户/口令。因为它的加密密钥独立于口令,所以如果口令失密,我们可以迅速改变口令而无需重新加密整个硬盘。通过提供一个标准的磁盘上的格式,它不仅方便之间分布的兼容性,而且还提供了多个用户密码的安全管理。必须首先对加密的卷进行解密,才能挂载其中的文件系统。

工具:cryptsetup(默认已经安装)

常用参数:luksFormat、luksOpen、luksClose、luksAddKey

使用cryptsetup对分区进行了加密后,这个分区就不再允许直接挂载。LUKS也是一种基于device mapper 机制的加密方案。如果要使用这个分区,必须对这个分区做一个映射,映射到/dev/mapper这个目录里去,,我们只能挂载这个映射才能使用。然而做映射的时候是需要输入解密密码的。

注:要解除加密需要备份分区内的文件再重新格式化LUKS分区

Crypsetup工具加密的特点:

Ø加密后不能直接挂载

Ø加密后硬盘丢失也不用担心数据被盗

Ø加密后必须做映射才能挂载

格式化LUKS分区 [root@rhel6 ~]# cryptsetup luksFormat /dev/vda8 //将分区进行LUKS格式(变成LUKS分区) WARNING! ======== This will overwrite data on /dev/vda8 irrevocably.

Are you sure? (Type uppercase yes): YES //输入大写的YES Enter LUKS passphrase: //输入两次密码 Verify passphrase:

映射分区 [root@rhel6 ~]# cryptsetup luksOpen /dev/vda8 luks_test //打开LUKS分区,将在/dev/mapper/目录中生成一个luks_test的文件 Enter passphrase for /dev/vda8: //必须输入luks密码才能打开LUKS分区

格式化、挂载、使用分区 [root@rhel6 ~]# mkfs.ext4 /dev/mapper/luks_test [root@rhel6 ~]# mount /dev/mapper/luks_test /luks/

关闭映射,先卸载后关闭 [root@rhel6 ~]# umount /luks/ [root@rhel6 ~]# cryptsetup luksClose luks_test //关闭LUKS分区 [root@rhel6 ~]# mount /dev/vda8 /luks/ //无法直接挂载/dev/vda8分区 mount: unknown filesystem type ‘crypto_LUKS’

实现开机自动挂载LUKS分区: [root@rhel6 ~]# dd if=/dev/urandom of=keyfile bs=1k count=4 4+0 records in 4+0 records out 4096 bytes (4.1 kB) copied, 0.00206882 s, 2.0 MB/s [root@rhel6 ~]# cryptsetup luksAddKey /dev/vda8 keyfile Enter any passphrase: [root@rhel6 ~]# vi /etc/crypttab name /dev/vda8 /root/keyfile luks [root@rhel6 ~]# vi /etc/fstab/dev/mapper/name /luks ext4 _netdev 0 0

添加/移除/修改LUKS密码 [root@rhel6 ~]# cryptsetup luksAddKey /dev/vda8 Enter any passphrase: Enter new passphrase for key slot: Verify passphrase: [root@rhel6 ~]# cryptsetup luksRemoveKey /dev/vda8 Enter LUKS passphrase to be deleted: [root@rhel6 ~]# cryptsetup luksAddKey /dev/vda8 keyfile Enter any passphrase:

坐在外婆的沙滩,看最白的帆影。

Linux下的磁盘加密LUKS

相关文章:

你感兴趣的文章:

标签云: