文章目录
前言:
实验步骤
1. 对磁盘进行分区格式化
2. 对新建的分区进行加密
3. 挂载测试
a) 加密情况下无法挂载:
b) 打开映射
c) 查看映射状态
d) 对映射进行格式化和挂载
e) 对格式化后映射进行挂载
使用crysetup关闭分区
总结
前言:
因为保密需要,一般系统会对文件或者磁盘进行加密。 今天我们来一起讨论下Linux磁盘的加密技术。
工具: cryptsetup
原理:
cryptsetup其实是一种设备的映射关系,我们用它来把一个设备映射成另外一个设备,然后对这个新的设备进行操作,并进行加密,这样就不会使我们的原设备直接被使用,从而达到一种安全的效果。
实验步骤
- 对磁盘进行分区格式化
- 对新建的分区进行加密
- 映射挂载测试
1. 对磁盘进行分区格式化
分区格式化操作是不是熟了,我们再来看一下:
[root@gaosh-1 ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G
Command (m for help): w
The partition table has been altered!
[root@gaosh-1 ~]#
格式化分区
2. 对新建的分区进行加密
3. 挂载测试
a) 加密情况下无法挂载:
b) 打开映射
[root@gaosh-1 ~]# cryptsetup luksOpen /dev/sdb1 my_disk
Enter passphrase for /dev/sdb1:
[root@gaosh-1 ~]# ll /dev/mapper
总用量 0
crw-rw----. 1 root root 10, 58 6月 28 21:14 control
lrwxrwxrwx. 1 root root 7 6月 28 21:31 my_disk -> ../dm-0
[root@gaosh-1 ~]#
c) 查看映射状态
[root@gaosh-1 ~]# cryptsetup status my_disk
/dev/mapper/my_disk is active.
type: LUKS1
cipher: aes-cbc-essiv:sha256
keysize: 256 bits
device: /dev/sdb1
offset: 4096 sectors
size: 20976794 sectors
mode: read/write
d) 对映射进行格式化和挂载
e) 对格式化后映射进行挂载
可以看到已经挂载成功,挂载的是一种映射关系,而不是硬盘本身
使用crysetup关闭分区
这里用的是luksClose ,关闭映射分区后,之前的映射分区就不存在了。
总结
本文主要总结了文章的加密技术,除了加密磁盘外,我们也可以用来加密u盘,算是比较方便的。