不能让随便什么人都可以进入磁盘,不然很有可能会导致一些危险的事情发生,所以,我们要学会对磁盘进行加密保护。
[root@localhost ~]# fdisk /dev/vdb ##建一个id1
Welcome to fdisk (util-linux 2.23.2).[root@localhost ~]# partprobe ##手动同步分区
[root@localhost ~]# cryptsetup luksFormat /dev/vdb1 ##LUKS加密/mnt/:
[root@localhost ~]# mkfs.xfs /dev/mapper/westos ##格式化file1 file2 file3
[root@localhost ~]#df
[root@localhost ~]# ls /mnt/
[root@localhost ~]# vim /root/diskpass ##名字随便起
##内容: westos123
[root@localhost ~]# chmod 600 /root/diskpass
[root@localhost ~]# cryptsetup luksAddKey /dev/vdb1 /root/diskpass
Enter any passphrase:
[root@localhost ~]# vim /etc/crypttab
##内容: westos /dev/vdb1 /root/diskpass
[root@localhost ~]# vim /etc/fstab
##内容: /dev/mapper/westos /mnt xfs defaults 0 0
[root@localhost ~]# df ##没有挂载
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3760316 6713584 36% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12752 472180 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
[root@localhost ~]# reboot ##重启
Connection to 172.25.254.229 closed by remote host.
Connection to 172.25.254.229 closed.
[root@foundation29 ~]# rht-vmctl view server
[root@foundation29 ~]# ssh [email protected]
[email protected]'s password:
Last login: Mon Apr 30 03:02:32 2018 from 172.25.254.29
[root@localhost ~]# df ##查看,挂载上了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3760488 6713412 36% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 136 484796 1% /dev/shm
tmpfs 484932 12804 472128 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/westos 1018540 32928 985612 4% /mnt
[root@localhost ~]# vim /etc/crypttab ##内容全部删掉
[root@localhost ~]# vim /etc/fstab ##内容全部删掉
[root@localhost ~]# rm -fr /root/diskpass ##删掉
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3761212 6712688 36% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 84 484848 1% /dev/shm
tmpfs 484932 12800 472132 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/westos 1018540 32928 985612 4% /mnt
[root@localhost ~]# umount /mnt/ ##卸载挂载
[root@localhost ~]# cryptsetup close westos ##关闭
[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=64000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=256000, 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 ~]# df ##没有了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3760752 6713148 36% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 84 484848 1% /dev/shm
tmpfs 484932 12796 472136 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup