Created
January 5, 2021 10:26
-
-
Save dsecuma/6b759962a2a383b784d7847ed2247c11 to your computer and use it in GitHub Desktop.
LUKS portable vol
This file contains 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/bash | |
FILENAME="private.img"; | |
FILESIZE="100M"; | |
# Create encrypted volume if it doesn't exist | |
if [ ! -f $FILENAME ]; then | |
echo "Creating image file..."; | |
dd if=/dev/zero of=$FILENAME bs=$FILESIZE count=0 seek=1 | |
echo "Setting permissions..."; | |
chmod 600 $FILENAME; | |
echo "Mounting image file..."; | |
sudo losetup -D; | |
sudo losetup /dev/loop0 $FILENAME; | |
echo "Encrypting image file..."; | |
sudo cryptsetup -q -y luksFormat /dev/loop0; | |
echo "Opening encrypted volume..."; | |
sudo cryptsetup luksOpen /dev/loop0 encrypted; | |
echo "Zeroing encrypted volume..."; | |
sudo dd if=/dev/zero of=/dev/mapper/encrypted; | |
echo "Formatting encrypted volume..."; | |
sudo mkfs.ext4 -L "encrypted" /dev/mapper/encrypted; | |
echo "Closing encrypted volume..."; | |
sudo cryptsetup luksClose /dev/mapper/encrypted; | |
sudo losetup -D; | |
fi | |
echo "Mounting image file..."; | |
sudo losetup -D; | |
sudo losetup /dev/loop0 $FILENAME; | |
echo "Decrypting image file..."; | |
sudo cryptsetup luksOpen /dev/loop0 encrypted; | |
echo "Mounting encrypted volume..."; | |
sudo mount /dev/mapper/encrypted /mnt/encrypted; | |
vim -i NONE -c 'set noswapfile' -c 'set nobackup' -c 'set noundofile' --cmd 'set undodir=/dev/null' /mnt/encrypted/; | |
echo "Unmounting encrypted volume..."; | |
sudo umount /mnt/encrypted; | |
echo "Closing encrypted volume..."; | |
sudo cryptsetup luksClose /dev/mapper/encrypted; | |
echo "Unmounting image file..."; | |
sudo losetup -D; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment