Skip to content

Latest commit

 

History

History
84 lines (56 loc) · 1.37 KB

encrypted-file-container.md

File metadata and controls

84 lines (56 loc) · 1.37 KB

Encrypted file container using LUKS

Installations

apt-get install cryptsetup

Create an empty file with the size of your container

fallocate -l 100M mycontainer.img

or

dd if=/dev/urandom of=mycontainer.img bs=1M count=100

Using a keyfile

dd if=/dev/urandom of=mykey.key bs=1024 count=1

Encrypting disk image file

cryptsetup -y luksFormat mycontainer.img

or

cryptsetup luksFormat -d mykey.key mycontainer.img

Unlock/Open LUKS encrypted container

  • creates a device file with the name /dev/mapper/myVolume
cryptsetup luksOpen mycontainer.img myVolume

or

cryptsetup luksOpen mycontainer.img -d mykey.key myVolume

Create an ext4 filesystem on the decrypted LUKS container

mkfs.ext4 /dev/mapper/myVolume

Mount the device

mkdir ~/myPrivData
mount /dev/mapper/myVolume ~/myPrivData
chown -R $USER ~/myPrivData

Unmount/close decrypted LUKS container

umount ~/myPrivData && cryptsetup luksClose myVolume && rm -rf ~/myPrivData

Quickly Access Container

cryptsetup luksOpen mycontainer.img myVolume && mkdir ~/myPrivData && mount /dev/mapper/myVolume ~/myPrivData

or

cryptsetup luksOpen mycontainer2.img -d mykey.key myVolume && mkdir ~/myPrivData && mount /dev/mapper/myVolume ~/myPrivData