For some time I have being thinking of the idea to have a portable encrypted vault file that could be used to store sensitive information on a portable usb stick, and I have finally figured out a way to do so. Here are the instructions:
dd if=/dev/urandom of=/path/to/master.keyfile bs=16384 count=1
This will generate a 16384 byte key file, that I can encrypt with gnupg for
extra security.
dd if=/dev/zero of=/path/to/vault_file bs=1 count=0 seek=60G
Tip: name the vault file something that must disguise it, like movie.mp4
, e.g.
This will create a file with 60 GB.
sudo cryptsetup -y -c aes-xts-plain64 -s 512 -h sha512 -i 5000 --use-random luksFormat /path/to/vault_file /path/to/master.keyfile
This will format the vault and encrypt it using the master key file.
sudo cryptsetup luksOpen /path/to/vault_file VAULT --key-file /path/to/master.keyfile
This will unlock the vault with the key file under the alias “VAULT”, which will allow us to format the vault file.
sudo mkfs.ext4 /dev/mapper/VAULT
$ sudo mkdir /tmp/VAULT
$ sudo mount /dev/mapper/VAULT /tmp/VAULT
$ sudo chown -R $(id -u):$(id -g) 600 /tmp/VAULT
Now you can use your vault, under the directory /tmp/VAULT
.
$ sudo umount /tmp/VAULT && sudo cryptsetup luksClose VAULT
sudo cryptsetup luksOpen /path/to/vault_file VAULT --key-file /path/to/master.keyfile && sudo mount /dev/mapper/VAULT /tmp/VAULT
This will unlock the vault with the key file under the alias “VAULT”. After you
finish, unmount and close it (step 7 above).