Do you have sensitive or critical information on your computer that you want to protect? Store it in an encrypted container!

An encrypted container is an authenticated and encrypted file that allows you to store sensitive files within it. This encrypted container can only be accessed with the right software and password (or decryption key). Think of an encrypted container as a virtual safe or vault. The purpose of encrypted containers is to secure data and prevent malware and intruders from accessing it.

Today we will show you how to create your own encrypted container in Linux using LUKS. 

 

STEP 1: First, we will need to create an image container. Use the seek value to specify the size—1GB in our case.

dd if=/dev/zero of=encrypted.img bs=1 count=0 seek=1G 

 

STEP 2: Next, we want to create a key file that will unlock the container. It could be anything you desire—your favourite song, image, document, or any other file. We will use /dev/random to randomize our key. 

dd if=/dev/urandom of=secret.bin bs=1024 count=1 

 

STEP 3: Next, we will encrypt our container. Make sure to type YES when prompted. 

sudo cryptsetup luksFormat encrypted.img secret.bin 

 

STEP 4: Now, we can unlock our container using our secret key, but we still need to format it with a proper filesystem. myEncryptedVolume can be any friendly name that we will use later to mount. 

sudo cryptsetup luksOpen encrypted.img myEncryptedVolume –key-file secret.bin 

 

STEP 5: Format the volume with ext4 filesystem.

sudo mkfs.ext4 /dev/mapper/myEncryptedVolume 

 

STEP 6: Now, we can mount the container just like a regular disk. 

sudo mount /dev/mapper/myEncryptedVolume $HOME/Private/ 

 

That’s all! To unmount and close the container use the following commands. 

sudo umount $HOME/Private 

sudo cryptsetup luksClose myEncryptedVolume 

 

Stuck on a step? We can assist you. Just ask us in the comments below.