Skip to content

Instantly share code, notes, and snippets.

@xardit
Created May 25, 2016 21:00
Show Gist options
  • Save xardit/244b53e24ae6fa9f1e7170386651d304 to your computer and use it in GitHub Desktop.
Save xardit/244b53e24ae6fa9f1e7170386651d304 to your computer and use it in GitHub Desktop.
### create encrypted USB
# reset nad create partition to the usb drive
fdisk /dev/sdb
##type 'o' to reset the table > 'n'ew > 'p'rimary partition > type 'w' to save
# format partition with luks & encrypt
cryptsetup luksFormat /dev/sdb1
# mount & format fs
cryptsetup luksOpen /dev/sdb1 luks1c/
mkfs.ext4 /dev/mapper/luks1
#close it
cryptsetup luksClose luks1
#################################################
### create encrypted FILE
# create file
dd if=/dev/zero of=~/luks.img bs=1 count=0 seek=256MB
sel
# mount file as device
losetup -f #find an unused loop dev
losetup /dev/loop0 ~/luks.img
# format partition with luks & encrypt
cryptsetup luksFormat /dev/loop0
# mount & format fs
cryptsetup luksOpen /dev/loop0 luks2
mkfs.ext4 /dev/mapper/luks2
#close it
cryptsetup luksClose luks2
#################################################
### NUKE it
#dump header
cryptsetup luksDump /dev/sdb1
#create nuke
cryptsetup luksAddNuke /dev/sdb1
#save header & encrypt headere
cryptsetup luksHeaderBackup --header-backup-file luksheader.back /dev/sdb1
openssl enc -aes-256-cbc -salt -in luksheader.back -out luksheader.back.enc
#decrypt & restore header
openssl enc -d -aes-256-cbc -in luksheader.back.enc -out luksheader.back
cryptsetup luksHeaderRestore --header-backup-file luksheader.back /dev/sdb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment