Skip to content

Instantly share code, notes, and snippets.

@dingyaguang117
Created December 12, 2015 10:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dingyaguang117/74dbe459a2b31e2e5213 to your computer and use it in GitHub Desktop.
Save dingyaguang117/74dbe459a2b31e2e5213 to your computer and use it in GitHub Desktop.
ubuntu 使用dm-crypt 加密目录,并且开机自动加载
=========== 文件磁盘========
---- 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