Encrypting and decypting a flash drive
Posted on February 22, 2020
Tags: Encryption, Decryption
Note:
- You need root for most of these commands
- Replace X with the target drive letter
Encrypting a flash drive that was previously unencrypted
Install cryptsetup
pacman -S cryptsetup
List your USB devices with either
lsblk
or
fdisk -l
Write random data to disk
shred -v -n 1 /dev/sdX
or
dd if=/dev/urandom of=/dev/sdX bs=1M
Set up a new dm-crypt device in LUKS encryption mode
cryptsetup luksFormat /dev/sdX
Set up mapping
cryptsetup luksOpen /dev/sdX flashy
Verify the new virtual block device mapper
ls -arlt /dev/mapper | tail
Format the disk with ext4
mkfs -t ext4 /dev/mapper/flashy
Create a mount location
mkdir /run/mount/flashy
Mount the device your filesystem:
mount /dev/mapper/flashy /run/mount/flashy
Verify the the mapper is properly mounted using the df command:
df -h /run/mount/flashy
Accessing your flash drive later on.
Decrypt the flash drive
cryptsetup luksOpen /dev/sdX flashy
Look it up
ls -arlt /dev/mapper | tail
Create a mount location
mkdir /run/mount/flashy
Mount the flash drive
mount /dev/mapper/flashy /run/mount/flashy
Access your files
cd /run/mount/flashy
Unmount the flash drive
umount /run/mount/flashy
Cleaup
rm -r /run/mount/flashy
Close your flash drive
cryptsetup luksClose flashy