Linux 基础 之 磁盘加密保护(LUKS加密)和 开机自动挂载

本文介绍了如何在Linux系统中使用LUKS加密磁盘以增强数据安全性,并详细阐述了设置开机自动挂载加密磁盘的步骤,包括LUKS加密、添加密钥、配置crypttab和fstab文件,以及取消加密保护的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不能让随便什么人都可以进入磁盘,不然很有可能会导致一些危险的事情发生,所以,我们要学会对磁盘进行加密保护。

一、加密保护

步骤:

[root@localhost ~]# fdisk /dev/vdb                 ##建一个id1

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00012042

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   83  Linux

Command (m for help): wq
The partition table has been altered!

[root@localhost ~]# partprobe          ##手动同步分区


[root@localhost ~]# cryptsetup luksFormat /dev/vdb1     ##LUKS加密

Are you sure? (Type uppercase yes): YES   ##必须大写
Enter passphrase:
Verify passphrase:
[root@localhost ~]# cryptsetup open /dev/vdb1 westos    ##把这个打开 ##westos名字随便起
Enter passphrase for /dev/vdb1:
[root@localhost ~]# ls /dev/mapper/westos /mnt/   
/dev/mapper/westos

/mnt/:


[root@localhost ~]# mkfs.xfs /dev/mapper/westos     ##格式化
[root@localhost ~]# mount /dev/mapper/westos /mnt/       ##挂载到/mnt
[root@localhost ~]# touch /mnt/file{1..3}          ##就可以建立文件了
[root@localhost ~]# ls /mnt/              ##建立成功了

file1  file2  file3

[root@localhost ~]#df

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值