Task: in CentOS 6.x system, set up and mount automatically encrypted filesystem, residing within a regular file, using one-time (random) key.
/etc/crypttab in CentOS 6.* doesn't allow using plain file as block device to mount and map automatically.
So, /etc/crypttab line like this
cfs /var/file-with-encrypted-filesystem some-password-source
gets ignored in CentOS.
The following sequence of commands can be used to do the task in CentOS:
losetup /dev/loop0 /var/tmpfile dd if=/dev/urandom of=/dev/shm/tmppass bs=512 count=1 cryptsetup luksFormat /dev/loop0 --use-urandom --batch-mode --key-file /dev/shm/tmppass cryptsetup luksOpen /dev/loop0 ctmp --batch-mode --key-file /dev/shm/tmppass mkfs.ext2 /dev/mapper/ctmp mount -t ext2 /dev/mapper/ctmp /mountpoint shred -n 1 /dev/shm/tmppass rm -f /dev/shm/tmppass
assuming file to hold filesystem is /var/tmpfile
Is there less cumbersome way to achieve the same in Debian-like way (specifying relevant entries in /etc/crypttab and /etec/fstab )?