Linux Foo - Manage LUKS key
I assume this is a bit of a dated set of procedures... as-in, there is probably a better way to deal with LUKS nowadays. Also - at some point I will (hopefully) be writing a blog entry about LUKS key accessed from centralized key server.
Assessment
cryptsetup luksDump /dev/sda1
cryptsetup luksOpen --test-passphrase --key-slot 3 --key-file /root/.keyfile /dev/sda1
Setup
# If there is already a crypttab, update it... otherwise, create a new one
if [ -f /etc/crypttab ]
then
sed -i -e '1i# <target name> <source device> <key file> <options>' /etc/crypttab
else
echo "# <target name> <source device> <key file> <options> " > /etc/crypttab
fi
# Create a "key file" and add it to the device (interactive step)
dd if=/dev/urandom of=/root/.keyfile bs=32 count=1
chmod 0400 /root/.keyfile
cryptsetup luksFormat /dev/sdb
for DEV in `lsblk | grep -B1 luks | egrep 'lvm|part' | awk '{ print $1 }' | sed 's/├─//g' | sed 's/└─//g'`
do
echo cryptsetup luksAddKey /dev/mapper/${DEV} /root/.keyfile
done
# If there is already entries in the cryptab file
sed -i -e 's/none/\/root\/.keyfile/g' /etc/crypttab
chmod 0744 /etc/crypttab
dracut --force --install /root/.keyfile /boot/initramfs-`uname -r`.img
echo "cryptsetup luksAddKey /dev/sdb1 /root/.keyfile"
echo "cryptsetup --key-file /root/.keyfile luksOpen /dev/sdb1 DATA"
echo "DATA UUID=c963bd90-a5bf-4616-b44e-24dc41af2fba /root/.keyfile luks" >> /etc/crypttab
mkdir /data
echo "/dev/mapper/DATA /data xfs rw,nosuid,nodev,relatime,nofail 1 2" >> /etc/fstab
mount -a
Comments
Post a Comment