Container encryption using cryptsetup
How to encrypt a container using cryptsetup
Last updated
Was this helpful?
How to encrypt a container using cryptsetup
Last updated
Was this helpful?
For disk encryption we will have these choices
Container encryption ( a single file )
A partition encryption ( whole partition )
Whole disk encryption ( excluding boot )
Full disk encryption ( including boot )
This instruction is about container encryption which simply means a single mountable file like an image file that we have with docker container.
This guide is for Debian based distribution, for others may not be the same steps.
cryptsetup
Simply we can install it
and the command will be installed, then use it cryptsetup
Then using dd
or fallocate
we can create a single file with desired size e.g. 512M
and with fallocate
or it can be other places e.g. /
which we should be root
to do so
With this single 512M file we have, we will next create a LUKS partition
then cryptsetup
asks you for confirmation and you should type in YES in uppercase and then it asks you for the passphrase with which later this volume / container is going be for decrypted.
After adding LUKS on top the volume, we can open it using
The <NAME>
can be your desired name, just notice with are dealing with special devices and /dev
so we need root
permission. After opening it we will see it in /dev/mapper
here derak is the name (<NAME>
) I entered for the volume, you will have a different name.
Now that we have the device (it is like a partition) we can mount
it like other partitions
Here is quick check
After you checked it with df -h
then we can cd
to /media
and create file or cp
other files into /media
When we are done with adding / removing file into our volume, we can umount it
Optionally we can check our mapped device befor closing it. Here for me ithe name is derak
Then close it
And check the device again, which we should not have it
and