Difference between revisions of "LUKS"
Jump to navigation
Jump to search
(Created page with "https://opensource.com/article/21/4/linux-encryption") |
|||
Line 1: | Line 1: | ||
https://opensource.com/article/21/4/linux-encryption | https://opensource.com/article/21/4/linux-encryption | ||
+ | |||
+ | |||
+ | # More | ||
+ | ``` | ||
+ | #!/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; | ||
+ | ``` |
Revision as of 22:06, 10 October 2023
https://opensource.com/article/21/4/linux-encryption
More
#!/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;