Created
December 12, 2015 10:45
-
-
Save dingyaguang117/74dbe459a2b31e2e5213 to your computer and use it in GitHub Desktop.
ubuntu 使用dm-crypt 加密目录,并且开机自动加载
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=========== 文件磁盘======== | |
---- init ---- | |
#安装依赖 | |
sudo apt-get install cryptsetup | |
#虚拟磁盘并格式化 | |
sudo fallocate -l 512M /root/home | |
sudo cryptsetup -y luksFormat /root/home | |
# 添加keyfile | |
dd if=/dev/urandom of=/root/keyfile bs=1 count=256 | |
sudo cryptsetup luksAddKey /root/home /root/keyfile | |
#打开虚拟磁盘 | |
sudo cryptsetup luksOpen /root/home home --key-file /root/keyfile | |
#格式化 | |
sudo mkfs.ext4 -j /dev/mapper/home | |
# 挂在 | |
sudo mount /dev/mapper/home /mnt/home | |
------ close ---- | |
sudo umount /mnt/home | |
sudo cryptsetup luksClose home | |
---- reopen ---- | |
sudo cryptsetup luksOpen /root/home home | |
sudo mount /dev/mapper/home /mnt/home | |
--- auto mount --- | |
# /etc/fstab 添加如下 | |
# <file system> <mount point> <type> <options> <dump> <pass> | |
/dev/mapper/home /mnt/home ext4 defaults 1 2 | |
# etc/crypttab 添加如下 | |
# <target name> <source device> <key file> <options> | |
home /root/home /root/keyfile luks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment