Skip to content

Instantly share code, notes, and snippets.

@snorfsneflin
Created January 16, 2016 22:40
Show Gist options
  • Save snorfsneflin/6051f76a9f7228f1674b to your computer and use it in GitHub Desktop.
Save snorfsneflin/6051f76a9f7228f1674b to your computer and use it in GitHub Desktop.
LUKS (Linux Unified Key Setup-on-disk-format) Encryption Examples
#!/bin/bash
#install cryptsetup
apt-get install cryptsetup
#initializes the volume, and sets an initial key or passphrase
cryptsetup -y -v luksFormat /dev/xvdc
#the following command create a mapping
cryptsetup luksOpen /dev/xvdc backup2
#status of mapping
cryptsetup -v status backup2
#dump LUKS headers
cryptsetup luksDump /dev/xvdc
#fill LUKS partition with zeros
#the bigger the storage size, the longer this will take (run in background, or use a progress monitor)
dd if=/dev/zero of=/dev/mapper/backup2
#format partition
mkfs.ext4 /dev/mapper/backup2
#mount new file system
mkdir /backup2
mount /dev/mapper/backup2 /backup2
df -H
cd /backup2
ls -l
#unmount partition
umount /backup2
cryptsetup luksClose backup2
#mount encrypted partition
cryptsetup luksOpen /dev/xvdc backup2
mount /dev/mapper/backup2 /backup2
df -H
mount
#run fsck
umount /backup2
fsck -vy /dev/mapper/backup2
mount /dev/mapper/backup2 /backup2
#add a pass, up to 8 passwords can be used
cryptsetup luksDump /dev/xvdc
cryptsetup luksAddKey /dev/xvdc
#delete a pass
cryptsetup luksRemoveKey /dev/xvdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment