linux LUKS cheatsheet

how to create and use a disk encrypted with LUKS on linux. for this example, assume a spare usb drive attached as /dev/sdb that containing the partition to be encrypted, /dev/sdb1. the decrypted name used by device mapper is usbdisk.

create the disk

# encrypt a partition with a password
cryptsetup luksFormat /dev/sdb1
# map the decrypted disk
cryptsetup luksOpen /dev/sdb1 usbdisk
# format as usual (the decrypted device)
mkfs.ext4 /dev/mapper/usbdisk


mount -t ext4 /dev/mapper/usbdisk /mnt


umount /mnt
cryptsetup luksClose usbdisk