磁盘的加密
1、给磁盘加密
创建新的磁盘,创建成功直接加密,加密后再进行格式化挂载(图1)
2、打开磁盘并生成加密文件
查看虚拟磁盘文件
3、格式化并挂载磁盘文件(虚拟磁盘)
4、此时可以通过挂载点查看磁盘内容或添加文件
5、若不想被别人看到磁盘内容可以卸掉挂载并关闭加密
卸掉挂载
[root@localhost ~]# umount /mnt
[root@localhost ~]# ls /mnt
[root@localhost ~]#
关闭加密
[root@localhost ~]# cryptsetup close westos
[root@localhost ~]#
关闭掉加密后再进行挂载时出错
[root@localhost ~]# mount /dev/vdb1 /mnt
mount: unknown filesystem type 'crypto_LUKS'
[root@localhost ~]#
6、开机挂载加密磁盘
需关闭加密及卸载之前的挂载
(1)将挂载写入挂载文件
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]#
(2)设置/etc/crypttab 配置文件
[root@localhost ~]# vim /etc/crypttab
[root@localhost ~]#
(3)创建/root/vdb1pass文件,写入加密密码
[root@localhost ~]# vim /root/vdb1pass
[root@localhost ~]#
123westos(密码)
(4)关联/dev/vdb1和 /root/vdb1pass
(5)重启无报错则成功
7、将加密设备改为普通设备
(1)删除开机挂载
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]#
#/dev/mapper/disk /mnt xfs defaults 0 0
(2)删除配置文件内容
[root@localhost ~]# vim /etc/crypttab #无法注释只能删除
[root@localhost ~]#
(3)卸掉挂载
[root@localhost ~]# umount /mnt
[root@localhost ~]# ls /mnt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3159252 7314648 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12768 472164 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
[root@localhost ~]#
(4)关闭解密设备
[root@localhost ~]# umount /mnt
[root@localhost ~]# ls /mnt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3159252 7314648 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12768 472164 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
[root@localhost ~]# cryptsetup close disk
[root@localhost ~]# mkfs.xfs /dev/vdb1 ##普通压缩
mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (crypto_LUKS).
mkfs.xfs: Use the -f option to force overwrite.
[root@localhost ~]# mkfs.xfs /dev/vdb1 -f ##强制压缩
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]#
(5)普通挂载
root@localhost ~]# mount /dev/vdb1 /mnt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3159516 7314384 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12768 472164 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/vdb1 508588 25760 482828 6% /mnt
[root@localhost ~]#