Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active March 13, 2023 16:26
Show Gist options
  • Save npodonnell/6f802944a94c64d5ee9430eae70036ae to your computer and use it in GitHub Desktop.
Save npodonnell/6f802944a94c64d5ee9430eae70036ae to your computer and use it in GitHub Desktop.
LUKS Encryption Cheatsheet

LUKS Encryption Cheatsheet

N. P. O'Donnell, 2021

Before you do anything, ensure you have cryptsetup installed:

sudo apt-get install -y cryptsetup

Find out correct block device

Make sure you choose the correct disk:

lsblk

Format disk with LUKS+ext4

#!/usr/bin/env bash

DEVICE=sdx
NAME=storage

sudo cryptsetup -y -v luksFormat /dev/$DEVICE
sudo cryptsetup luksOpen /dev/$DEVICE $NAME
sudo cryptsetup config /dev/$DEVICE --label $NAME
sudo dd if=/dev/urandom of=/dev/mapper/$NAME bs=8M status=progress
sudo mkfs.ext4 /dev/mapper/$NAME
sudo e2label /dev/mapper/$NAME $NAME

Unlock, map and mount the disk

Unlock / Map:

sudo cryptsetup luksOpen /dev/$DEVICE $NAME

Enter passphrase when prompted.

Mount:

sudo mkdir -p /mnt/$NAME
sudo mount /dev/mapper/$NAME /mnt/$NAME
sudo chmod 777 /mnt/$NAME

Unmount:

cd
sudo umount /mnt/$NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment