Encrypt external HDD / flash drive with dm-crypt & LUKS

To encrypt the whole HDD or only one partition on an internal or external drive, there is always the same procedure. I have tested the following steps on an Arch Linux with systemd and GRUB2 running.

1. Find the correct device (eg. /dev/sdb1 as a second interal SATA-HDD):

lsblk

2. Consider overwriting your old or even new device. Find some hints in the Arch wiki.

3. Create the partitions you need. If you want to encrypt the whole disk, create only one big partiton using the whole space.

cfdisk

or whatever you prefer.

4. Encrypt the partition using LUKS, for example with AES 256 bit keylength:

cryptsetup -c aes-xts-plain64 -y -s 512 luksFormat /dev/sdXY

5. Open it, so it will be in /dev/mapper/mycryptedhdd:

cryptsetup luksOpen /dev/sdXY mycryptedhdd

6. Set up a filesystem on it:

mkfs.ext4 /dev/mapper/mycryptedhdd

7. Test mounting:

mount /dev/mapper/mycryptedhdd /mnt/
df -h

8. umount and close container:

umount /mnt/
cryptsetup luksClose /dev/mapper/mycryptedhdd

Automount encrypted HDDs with LUKS on bootup

1. Add a new line in /etc/crypttab (man crypttab) to encrypt and open it under /dev/mapper/mycryptedhdd during bootup. (This equals the manual step 5 form above):

mycryptedhdd	UUID=00000000-0000-0000-0000-000000000000	none	tries=3

Field 1: Choose a name for your LUKS container
Field 2: Identify the disk / partition you want to open (find your UUID with: $ blkid /dev/sdXY, or enter the path like /dev/sdXY)
Field 3: Path to the keyfile, or „none“ if you only use passwords
Field 4: Write your password wrong this often

2. Add a new line in /etc/fstab (man fstab) to automatically mount the LUKS container generated by crypttab:

/dev/mapper/mycryptedhdd		/mnt/tv      ext4        defaults    0   2

Field 1: Path to the LUKS container you created with the crypttab
Field 2: Path to the folder you want your LUKS container to be mounted to (folders must exist)
Field 3: Used filesystem (the one you used above in step 6)
Field 4, 5, 6: rtfm (man fstab) or trust the values I used

3. That’s all. Consider using keyfiles or take a look at PasswordAgents if you start hating to type your password ;)

Ein Kommentar

  1. […] Fuente: Encrypt external HDD / flash drive with dm-crypt & LUKS […]

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.