LUKS is short for "Linux Unified Key Setup". It is part of dm-crypt, which is part of the Linux kernel.
=> https://wiki.archlinux.org/title/Dm-crypt
LUKS lets you encrypt disks so that others can't access your files if you lose or sell a disk after use. By "disk", I mean external devices like HDD's, SSD's, or USB flash drives.
This is just for comparison to the actual roadmap in the next section. Steps marked as "(once)" are only needed during the setup; all other steps are needed every time you use a disk.
Use "fdisk DISK", where DISK is the device file name, e.g. "/dev/sda". Check the device file name with lsblk.
Inside fdisk, consult the help menu and do the following steps:
Use "cryptsetup luksFormat PARTITION", where PARTITION is the partition device file name, e.g. "/dev/sda1".
During the setup, you will be asked to choose a permanent passphrase. However, you can still change it afterwards with "cryptsetup luksChangeKey PARTITION".
Use "cryptsetup open PARTITION NAME", where PARTITION is defined as above and NAME is a temporary name of your choosing. (You won't need NAME again after unmapping, so it's not really important.) The decrypted partition will be mapped to the virtual partition "/dev/mapper/NAME". (That's what the "dm" in "dm-crypt" stands for: device mapper.)
To close and unmap the virtual partition, use "cryptsetup close NAME".
Use "mkfs.ext4 -L LABEL VIRTUAL_PARTITION", where VIRTUAL_PARTITION is the partition device file name, e.g. "/dev/sda1" (for an unencrypted partition) or "/dev/mapper/NAME" (for a decrypted LUKS partition mapped to a virtual one), and LABEL is a file system label of your choosing.
Unlike the NAME during the decryption/mapping step, the file system LABEL is permanent. Desktop environments like Xfce will show it in your file browser, and udisksctl (described below) will use it too. However, you can still change it with "e2label VIRTUAL_PARTITION LABEL".
Use "mount" and "umount" and consult the man pages.
Desktop environments like Xfce can do steps 4/6 and 8/9/10 with a simple click. To make them easier on the command line, I use udisks.
=> https://wiki.archlinux.org/title/Udisks
I use the following commands for the steps in question:
PARTITION, VIRTUAL_PARTITION, LABEL, and DISK are defined as above; udisksctl tells you which name to use for VIRTUAL_PARTITION when you run "udisksctl unlock -b PARTITION". USER is the name of the user running the command.
Two facts come in handy for automation now: (a) you can use the same name for DISK that you use for PARTITION, and (b) you can use "/dev/disk/by-uuid/UUID" for PARTITION and VIRTUAL_PARTITION, where UUID is their respective UUID. (You can find them out with "lsblk -f".) Unlike temporary device file names like "/dev/sda1", the UUID of a partition is permanent. This also lets you test if a specific disk is plugged in with "test -b /dev/disk/by-uuid/UUID", where UUID is the UUID of PARTITION.
Here is a script that does this for you:
=> /software/simple-scripts/plug.sh
EOF
text/gemini; lang=en
This content has been proxied by September (ba2dc).