How do I auto-mount LUKS partition?
Using pam-mount
You can use pam-mount to do this. It will hook into the login process and thus be able to use the entered password for mounting a luks partition. Here's how to set it up:
Create a test luks image
Skip this section if you have a LUKS-encrypted partition or image already
Create a file called .priv in your home directory with size 1GB:
truncate -s 1G ~/.priv
Format the image using LUKS and set a password (use the same as your login password):
cryptsetup luksFormat ~/.priv
Enable the image:
sudo cryptsetup luksOpen ~/.priv priv
Create a file system on the new device:
sudo mkfs.ext4 /dev/mapper/priv
Disable the image again:
sudo cryptsetup luksClose priv
Install and set up pam-mount
Install the package:
sudo apt install libpam-mount
Edit the configuration file /etc/security/pam_mount.conf.xml
and add the following line to it:
<volume path="~/.priv" mountpoint="~/priv" />
Add this right after where it says <!-- Volume definitions -->
. Notice the subtle but important difference in the path and mountpoint arguments. In your particular case you would use path="/dev/sdb7"
.
Now login to your machine and you should notice that it takes a little longer than usual. After successful login you can check, using the mount
command, that there is now a new file system mounted in your home. It should look similar to this:
/dev/mapper/_dev_loop3 on /home/seb/priv type ext4 (rw,relatime,data=ordered,helper=crypt)
Use for /home/USER
I am using this setup for mounting my home directory (/home/seb
) from a LUKS encrypted image on Ubuntu 18.04. pam_mount will also take care of unmounting the image after I log out. As such it is a nice way to get at least some encryption if during installation you did not choose full disk encryption.