Skip to content

Instantly share code, notes, and snippets.

@tnibert
Created July 22, 2018 04:29
Show Gist options
  • Save tnibert/63389b1546d8eb03e7b8fd3c83e2f0fe to your computer and use it in GitHub Desktop.
Save tnibert/63389b1546d8eb03e7b8fd3c83e2f0fe to your computer and use it in GitHub Desktop.
Create encrypted automounting disk on Linux
# wipe the disk
wipefs –a /dev/sda
parted /dev/sda mklabel gpt
parted /dev/sda mkpart logical ext4 0% 100%
mkdir /mnt/usb
cryptsetup luksFormat /dev/sda1 # type YES and then enter a password
dd if=/dev/urandom of=/root/keyfile bs=1024 count=4
chmod 0400 /root/keyfile
cryptsetup luksAddKey /dev/sda1 /root/keyfile #Enter passphrase
cryptsetup open /dev/sda1 encrypted
# create new ext4 filesystem
mkfs.ext4 /dev/mapper/encrypted
echo encrypted /dev/sda1 /root/keyfile luks >> /etc/crypttab
echo /dev/mapper/encrypted /mnt/usb ext4 defaults 0 2 >> /etc/fstab
mount /mnt/usb
# depending on your system, you may need to update your initramfs at this point
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment