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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay