DEV Community

Cover image for Using LUKS Encrypted πŸ” Disks w/ Linux 🐧 on The CLI
F1LT3R
F1LT3R

Posted on

Using LUKS Encrypted πŸ” Disks w/ Linux 🐧 on The CLI

In this scenario, I create an encrypted LUKS disk to periodically save the Documents/ folder with Rsync, from a computer that does not have a GUI.

Creating a LUKS Disk

# Snapshot the disk list
BEFORE=$(mktemp); lsblk > "$BEFORE"

# [PLUG IN DISK]

# Snapshot changed disk list
AFTER=$(mktemp); lsblk > "$AFTER"

# Show the disks changed
diff -U0 -w "$BEFORE" "$AFTER" | tail -n +4

# Remove tmps
rm "$BEFORE" "$AFTER"

# Setup luksFormat Disk
sudo cryptsetup luksFormat /dev/xvdj

# [TYPE "YES"]
# [Enter Password]
# [Enter Confirmation Password]

# Open Encrypted Partition
sudo cryptsetup luksOpen /dev/xvdj DATA

# Install XFS Tools is necessary 
sudo apt install xfsprogs

# Add XFS File System
# (sudo apt install xfsprogs)
sudo mkfs.xfs /dev/mapper/DATA
Enter fullscreen mode Exit fullscreen mode

Mounting a LUKS Disk

# Attach disk to Qube 

# Replace xvdi, DATA with actual names
sudo cryptsetup luksOpen /dev/xvdi DATA

# See drive on mapper
ls /dev/mapper/DATA

# Create mount point
sudo mkdir /media/user/DATA

# Mount the partition
sudo mount /dev/mapper/DATA /media/user/DATA

# Rsync ~/Documents, excluding node_modules
sudo rsync -av --exclude="node_modules:*.un~" ~/Documents /media/user/DATA
Enter fullscreen mode Exit fullscreen mode

Unmounting a LUKS Disk

# Unmount the disk
sudo umount /media/user/DATA

sudo rm -r /media/user/DATA

# Close the encrypted partition
sudo cryptsetup luksClose DATA
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay