An encrypted /home directory gets mounted automatically for me when I log in. I have a second internal hard drive that I've formatted and encrypted with Disk Utility. I want it to be automatically mounted when I login, just like my encrypted /home directory is. How do I do this?
There are several very similar questions here, but the answers don't apply to my situation. It might be best to close/merge my question here and edit the second one below, but I think it may have been abandoned (and therefore never to be marked as accepted).
This solution isn't a secure method, it circumvents the encryption.
This one requires editing fstab
, which necessitates entering an additional password at boot. It's not automatic like mounting /home.
This question is very similar, but does not apply to an encrypted drive. The solution won't work for my needs.
Here is one but it's for NTFS drives, mine is ext4.
I can re-format and re-encrypt the second drive if a solution requires this. I've got all the data backed up elsewhere.
When I wrote this answer a few years ago this was the best way of implementing the solution. I'd now suggest that you look at the next answer using mount.ecryptfs_private instead.
I was also looking for a way to automatically mount a second eCryptfs volume. The following collection of scripts and configuration modifications will securely and automatically mount your volume on login, either to the GUI or the CLI.
There is a better solution that's in the process of being created (though I think not quite ready for automatic mounting on user login, as such this script will have a limited shelf life.):
ecryptfs on too-small harddrive - how to add links into the encryption?
The security of the scripts depends on your home directory being encrypted with eCryptfs so that the script and files with the password to unwrap your passphrase are encrypted. If you leave your computer unlocked with a root shell open after log in it will be possible to access the passwords, however use of sudo NOPASSWD allows secure mounting of the partition without requiring password entry or leaving the passphrase in a file readable by the user.
One known deficiency of these scripts is that your second volume will not be unmounted on logout, as such it's not particularly suitable for multi user systems.
My solution is implemented with several parts, two shell scripts, one that performs the actual mounting and another that serves as a wrapper for it.
This is the wrapper script that validates if the directory is already mounted, if it isn't then it will call the mounting script using sudo:
/home/johnf/scripts/automount_ecryptfs
This script calls /home/johnf/scripts/mount_other_ecryptfs which is as follows.
Note that this script assumes that you have file name encryption enabled, if you don't it will be necessary to either modify the script to handle detection (look at ecryptfs-recover-private) or you could remove the ecryptfs_fnek_sig mount option.
The following is the /home/johnf/scripts/mount_other_ecryptfs script:
You will also need to create a file with your password in it, this file will be used by the eCryptfs mount command:
/home/johnf/scripts/ecryptfs_passphrase:
You need to modify the permissions on several files:
Before creating the scripts you need to create a sudoers configuration to permit the execution of the mounting script using sudo without entering your sudo password.
Add the following to /etc/sudoers (or a file in /etc/sudoers.d). You will want to replace johnf with your username. It's necessary to use an absolute path to the mounting script.
The final step is to call the automount_ecryptfs script on login.
On Ubuntu Unity (and probably gnome) use the Startup Applications applet to create a new startup program that calls /home/johnf/scripts/automount_ecryptfs.
To automatically mount the second eCryptfs volume on login into a bash shell you will want to modify your ~/.bashrc file. Add the following:
With this configuration in place you should now automatically mount your second eCryptfs volume.
Building on @johnf's answer but using mount.ecryptfs_private instead:
/home/bob/
(eg. on a SSD), using Ubuntu's normal encrypted home dir magic./media/hdd/bob_extra/
(eg. on a HDD), to be mounted to/home/bob/extra
. This should automount on login, just like the home dir does.create it
test it
running
mount
, you should see:to unmount:
setup automount
Create
/home/bob/bin/automount_ecryptfs.extra
, which will mount it if it hasn't been mounted already.Make it executable (
chmod +x
), then add it into/home/bob/.bashrc
:Then add it to Gnome's Startup Applications as well.
You no longer need the solutions above.
Prerequisites:
Note: this method is less secure than mounting an encrypted drive manually. If someone has physical access to your computer, you are careless with your root password, or your computer has multiple users/guest accounts, this method is not secure; the secondary drive stays mounted when you log out but do not shut down the system, so its contents are visible to other users.
Part 1: Encrypt the secondary drive.
Part 2: Automatically mount the HDD on system start-up.
You now have an encrypted hard drive that will automatically mount when your computer boots.
Create a script in your encrypted home directory:
~/scripts/mount_storage.sh
:Add to "Startup Applications":
Add to
/etc/sudoers
:You need to have created the
/storage
mount point and change UUID in the above script (find it withblkid
).Proceeding as follows should be secure. Requiring the passphrase stops other users from getting access to the volume, even though it is mounted.
1.Open Disks, choose the drive and click on the LUKS volume. Click on the cogwheels and unchoose "User Session Defaults". Choose "Unlock at system startup" and "Require additional authorization to unlock":
2.Click on the disk volume (below the LUKS volume). Click on the cogwheels and unchoose "User Session Defaults". Choose "Mount at system startup" and "Show in user interface":
You could also choose to require additional authentication to mount the volume, but in that case the mounting would not be automatic for the user in question.
I'm afraid that this isn't going to be a popular answer...
It's not going to be possible to automatically mount any encrypted partition, without circumventing the security of the encryption itself.
Think about what "automatically" means, and understand that automatically means that they will get to see your data too.
Updating on rcoup's anwser :
mount.ecryptfs_private
manpage, it will do nothing if the folder is already mounted, so it is not useful to check for that ;systemd
to auto-run it, as it will be independent from bash or the graphical session, and it also gives a convenient way to explicitly unmount at the end of the session.So we can do
systemctl --user edit --force --full mount-ecryptfs-extra.service
: this opens up an editor, in which we can typeThen
systemctl --user install mount-ecryptfs-extra.service
.