Created
June 26, 2017 01:20
-
-
Save ianhattendorf/fbd5eb460dbd6add43202e0c7d637579 to your computer and use it in GitHub Desktop.
LUKS helper scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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