Simple File Container Encryption
So recently I needed to create a simple encrypted file container. I remember looking at this a few years ago and most people were recommending TrueCrypt at the time but they've gone under apparently so I knocked up 3 simple scripts to make the container, open and mount it and unmount and close it again.
This version uses LUKS (Linux Unified Key Setup) format which should be around for a while.
My scripts are lazy and don't ask many questions or need much input. On the permissions side it makes the file open to everybody (but you still need a passphrase to access the encrypted content).
Essentially, the 'make_c.sh' script just creates a disk image, encrypts it with your passphrase and then formats the volume. It formats using the Ext 4 Linux format but you can change that to FAT (4GB file size limit) or the popular exFAT (you need to install exfatprogs on Ubuntu if you want that! - sudo apt install exfatprogs) to make it more portable. Just change the mkfs line in the script.
Then 'open_e.sh' script just unencrypts the volume and then mounts it as a disk.
'close_e.sh' just unmounts the volume then closes the encrypted container.
You do need Super User privileges to use these. Feel free to tighten up the permissions if it suits you!
I'm an Ubuntu for Desktop things over here so I've only tested it on that platform but it should work on any recent Debian flavour.
It won't handle certain circumstances so it's best suited when you want to just open 1 file at a time.
Make sure to use the close_e.sh to close your encrypted file after opening or it will stay open in /dev/mapper.
The files are commented so just change them to your needs.
You'll need cryptsetup installed:
sudo apt install cryptsetup-bin
I'm using version 2.7.0 apparently.
Here's the script files:
simple_file_encyption.zip
Remember to give them execute permissions for them to work.
Unzip them to a directory, then run:
chmod -R +x < your directory path >
...to make the files execute.
Usage is:
Create an encrypted file container:
make_e.sh < file path > < size (eg. 10G) >
Open and mount:
open_e.sh < file path >
Close and unmount:
close_e.sh < file path >
Aliases
In Ubuntu you can set up aliases in the .bash_aliases file (or .bashrc in other flavours of Linux) which makes it quick and easy to create, open and close encrypted file containers whenever you need to.nano ~/.bash_aliases
I added these lines:
alias mke="~/enc/make_e.sh" alias ope="~/enc/open_e.sh" alias cle="~/enc/close_e.sh"Obviously, substitute the file paths for your own (you can see my scripts are in ~/enc/). Save and close the file and then run a new terminal to pick up the changes.
So for example, to create a 10Gb encrypted file called 'ben', I'd navigate to the directory I want to create the file in, right-click / 'Open in terminal' to use the terminal there and type:
mke ben 10G
To mount it:
ope ben
And then when I'm finished close it:
cle ben
Super easy, barely an inconvenience!