LUKS(Linux 统一密钥设置)是标准的设备加密格式;
LUKS可以对分区或卷进行加密;
挂载分区的文件系统时,必须首先对加密的分区或卷进行解密;
ex:
1.创建一个新分区
[root@localhost ~]# fdisk /dev/sda
2.对新的分区进行加密,并设置密码
[root@localhost ~]# cryptsetup luksFormat /dev/sda6
WARNING!
========
This will overwrite data on /dev/sda6 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase: 123456
Verify passphrase: 123456
3.输入正确的密码解密,会将加密的分区解锁到 /dev/mapper/
[root@localhost ~]# cryptsetup luksOpen /dev/sda6 hidepart
Enter passphrase for /dev/sda6: 123456
[root@localhost ~]# ls /dev/mapper/hidepart
/dev/mapper/hidepart
4.给解密的块文件,创建ext3文件系统
[root@localhost ~]# mkfs -t ext3 /dev/mapper/hidepart
5.创建挂载点,并挂载文件系统。
[root@localhost ~]# mkdir /hidepart
[root@localhost ~]# mount /dev/mapper/hidepart /hidepart
6.使用后,卸载文件系统,并锁定加密设备
[root@localhost ~]# umount /hidepart
[root@localhost ~]# cryptsetup luksClose hidepart
[root@localhost ~]# mount /dev/sda6 /hidepart
mount: unknown filesystem type 'crypto_LUKS'
重启后挂载加密的分区
===============================================
1.在/etc/fstab 中添加挂载条目
[root@localhost ~]# cat /etc/fstab
... ... ...
/dev/mapper/hidepart /hidepart ext3 defaults 0 0
... ... ...
2.创建密码文件,注意密码文件的权限,并将密钥文件添加到LUKS的密钥。
[root@localhost ~]# echo "123456" > /root/123456
[root@localhost ~]# chown root /root/123456
[root@localhost ~]# chmod 600 /root/123456
[root@localhost ~]# cryptsetup luksAddKey /dev/sda6 /root/123456
Enter any passphrase: 123456
3.系统启动期间解锁的设备列表
1)启动时需要输入密码
[root@localhost ~]# cat /etc/crypttab
secret /dev/sda6
2)启动时自动加载密码
[root@localhost ~]# cat /etc/crypttab
secret /dev/sda6 /root/123456