I am in the process of eliminating non-free code from my machines.

I currently am using Veracrypt to lock some files behind encryption, and quite like that I have a .vc file I can easily backup and move.

I want to reproduce this with LUKS, however, all documentation I find make it look like it is aimed to encrypt devices, like USB keys, disks, partitions... Which is really useful, but does not lend itself to have a multitude of encrypted files, or easily making backup of thoses.

Can LUKS be used to have the filesystem in a encrypted file instead of a device ?

  • Uhm, your ambition is awesome, but what is it that you consider non-free about VeraCrypt? Because your question certainly suggests it is ... btw, if I were you I'd check out zuluCrypt and zuluMount which has support for a variety of containers, including VeraCrypt ones. I for one still prefer VeraCrypt as it would allow me to do it on multiple systems whereas LUKS once again would limit my choices. But YMMV, so just commenting here. Commented May 25, 2021 at 23:21

1 Answer 1


Yes it can. You can encrypt a file (but you need to have it already created), treating it like a regular block device. Here is a test I did with a zeroed out file that I created with dd.

  # dd if=/dev/zero of=./test.dd bs=1024 count=10000
  10000+0 records in
  10000+0 records out
  10240000 bytes (10 MB, 9.8 MiB) copied, 0.020574 s, 498 MB/s
  # cryptsetup luksFormat ./test.dd
  This will overwrite data on ./test.dd irrevocably.
  Are you sure? (Type uppercase yes): YES
  Enter passphrase for ./test.dd:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .