Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active January 1, 2016 19:29
Show Gist options
  • Select an option

  • Save obfusk/8190338 to your computer and use it in GitHub Desktop.

Select an option

Save obfusk/8190338 to your computer and use it in GitHub Desktop.
create an encrypted flash drive on the command line w/ cryptsetup

1. Prepare

$ modprobe dm-crypt
$ modprobe sha512
$ modprobe aes

2. Partition

$ fdisk /dev/sdX

3. Wipe FS

NB: this does not wipe data, just the previous filesystem information.

$ wipefs -a /dev/sdX1

4. Create Encrypted Volume

$ cryptsetup -c aes-xts-plain -s 512 -h sha512 -i 5000 --use-random -y -v luksFormat /dev/sdX1

5. Open Encrypted Volume

$ cryptsetup luksOpen /dev/sdX1 NAME

6. Create FS

$ mkfs.ext4 -v -L LABEL /dev/mapper/NAME

7. Chown + Chmod

NB: mount FS first.

You may want to chown and chmod the FS.

Close Encrypted Volume

NB: unmount FS first.

$ cryptsetup luksClose NAME

Encrypted Volume Info

$ cryptsetup luksDump /dev/sdX1

Encrypted Volume Status

$ cryptsetup status NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment