Skip to content

Instantly share code, notes, and snippets.

@ianhattendorf
Created June 26, 2017 01:20
Show Gist options
  • Save ianhattendorf/fbd5eb460dbd6add43202e0c7d637579 to your computer and use it in GitHub Desktop.
Save ianhattendorf/fbd5eb460dbd6add43202e0c7d637579 to your computer and use it in GitHub Desktop.
LUKS helper scripts
#!/bin/sh
set -e
set -u
FILENAME="${1-encrypted.img}"
FILESIZE="${2-32M}"
# Create encrypted volume if it doesn't exist
if [ ! -f "$FILENAME" ]; then
echo "Creating image file \"$FILENAME\" (size: $FILESIZE)..."
fallocate -l $FILESIZE "$FILENAME"
echo "Encrypting image file..."
sudo cryptsetup -y luksFormat "$FILENAME"
echo "Opening encrypted volume..."
sudo cryptsetup luksOpen "$FILENAME" encVolume
echo "Formatting encrypted volume..."
sudo mkfs.ext4 -L "encrypted" /dev/mapper/encVolume
echo "Closing encrypted volume..."
sudo cryptsetup luksClose /dev/mapper/encVolume
fi
echo "Opening image file..."
sudo cryptsetup luksOpen "$FILENAME" encVolume
echo "Mounting encrypted volume..."
mkdir -p ~/mnt/private/encrypted
chmod 700 ~/mnt/private
sudo mount /dev/mapper/encVolume ~/mnt/private/encrypted
echo "Done."
#!/bin/sh
set -e
set -u
FILENAME="${1-encrypted.img}"
echo "Unmounting image file"
sudo umount ~/mnt/private/encrypted
echo "Closing image file..."
sudo cryptsetup luksClose /dev/mapper/encVolume
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment