ecryptfs-setup-private
can do all those things for you, in a private folder called ~/.Private
that gets mounted as ~/Private
just use it, and we can modify it's folder names below.
Or even encrypt your entire home folder with ecryptfs-migrate-home
would be a good idea.
They'll both do exactly what you want, auto mounting on login & unmounting on logout. Why re-invent the wheel with your own potentially unsafe (password handling can be tricky) custom scripts? And unless you're using symbolic links, if you're copying files back & forth between plain folders and encrypted folders, you'll likely be leaving behind the unencrypted deleted files, just waiting to be read with an undelete or free space search command.
A solution is to use a ~/.Private
underlying directory containing encrypted data (OR a link from ~/.Private
to a different folder elsewhere), but change the mountpoint folder to a different one (thanks to Sebastian):
- Run
ecryptfs-setup-private
then
Move/create a new mountpoint folder
mv ~/Private /path/to/new/folder
Change the contents of ~/.ecryptfs/Private.mnt
(file containing path of the private directory mountpoint) to the new mountpoint folder
echo /path/to/new/folder > ~/.ecryptfs/Private.mnt
If the ~/.ecryptfs/auto-mount
and ~/.ecryptfs/auto-umount
files exist the folder will be automatically mounted/unmounted on login/logout.
For manual mounting/decrypting (password will be required), run ecryptfs-mount-private
For manual unmounting, run ecryptfs-umount-private