How to encrypt files in an image with Cryptmount?

encrypt files

At previous article we told you about Cryptmount which is a utility we have in Linux which gives us the possibility to create encryption file systems, which is quite useful when trying to protect our information from unauthorized people.

Well then in this new article we are going to see the possibility of being able to host files in an encrypted image With the help of this utility, for this we are going to make use of some additional tools which we already have within Linux.

The first step what we are going to do is create our container where the files that will be encrypted will be housed for this we will use the dd tool which will support us to create a blank image in which we can host our files and protect them in it.

For this we are going to create a file according to the size of the information to host Although we can give you a little more space for future editions, this is to your needs, we can take 100 MB as a basis for mere example.

For this we are going to open a terminal and we are going to execute the following command:

dd if = /dev/zero of = el-nombre-que-tu-quieras.img bs = 1M count = 100

Used cryptmount to encrypt files

Having the utility installed on our computer, vWe are going to edit a template which is in the following path:

/ etc / cryptmount / cmtab

It is important to remember that the edition of this must be done with super user permissions. They can do it with the editor of their choice. In this file we will find the following and we can edit it:

TARGET_NAME {
dev=DEVICE
flags=FLAG,FLAG,...
startsector=STARTSECTOR
numsectors=NUMSECTORS
loop=LOOPDEV
dir=MOUNT_POINT
fstype=TYPE
fsoptions=OPT,OPT,...
cipher=CIPHER
ivoffset=IVOFFSET
keyformat=KEYFORMAT
keyfile=KEYFILE
keyhash=KEYHASH
keycipher=KEYCIPHER
keymaxlen=KEYMAXLEN
passwdretries=NUMATTEMPTS
}

And based on the following and If you prefer, you can copy and paste, only edit the routes:

# /etc/cryptmount/cmtab
# example file - please modify before use
contenedor {
dev=/ruta/a/la/imagen/creada
fstype=ext4
mountoptions=defaults
cipher=aes # filesystem encryption
keyfile=/ruta/a/la/clave/de/tu/imagen.key
keyformat=builtin
}

You can change the name of "container" for whatever you want, you can add more parameters, if you want to know more about them I leave you the yesnext link.

encrypt on linux

Now we are going to proceed to configure the container for our files, the first step is to generate our password encryption which must be fully compatible with the encryption system that we choose, this in order to avoid possible errors.

For this, we are going to use the recommended encryption key, open a terminal and execute:

sudo cryptmount --generate-key 32 contenedor

When executing this command, immediately we will be asked to establish a password which we must remember or keep in a totally safe place.

Done this now we are going to execute the following command to prepare our container:

sudo cryptmount --prepare contenedor

This creates the device file, '/ dev / mapper / container', which allows us to create a filesystem.

Now we are going to proceed to create a system with mke2fs:

sudo mke2fs /dev/mapper/contenedor

And we execute:

sudo cryptmount --release contenedor

How to host the files in the encrypted image?

In order to start hosting the files that we want to protect in the encrypted image, first we must create the route where it will be mounted and dismantled and it will be the route in which we can work.

You can create the folder in the path you choose, for example within your personal folder, on another hard drive, etc.

For example, using the terminal you can run the following command:

mkdir carpetaprueba

And a folder called test folder will be created within your home directory.

If they want to create a folder within system folders they will require root and now we execute the following command:

cryptmount -m contenedor

Y now we can transfer user ownership with the following command:

sudo chown tunombredeusuario /tu/ruta/a/la/carpetaprueba

With this we will have the image mounted to start making transferring files to it, it is as if it were another folder where we can also modify, create or delete files contained there.

Finally, at the end of the work with the image we proceed to disassemble it with the following command:

cryptmount -u contenedor


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.