How to mount and unmount a LUKS encrypted USB
Published: 2021-12-03 | Last Updated: 2022-02-11 | ~2 Minute Read
Introduction
This is a very simple and to the point guide about how to use a LUKS encrypted drive from the command line. I write this since I recently had to use it and the specific commands escaped my memory due to not using this often enough.
For this you will need some programs installed on your computer, mainly cryptsetup
. Slackware has this program installed as part of its full installation.
Mounting the USB drive
In order to mount the USB drive you need to run the following as the root user:
# cryptsetup luksOpen /dev/sdx1 name-of-volume
Once you have done this, the mounting process should work the same as with non encrypted drives but using the /dev/mapper
mapper path as source:
# mount /dev/mapper/name-of-volume /tmp/usb-mount-folder
At this point you should be able to see the contents of the USB drive as usual.
Unmounting the USB drive
Once you are done using your USB drive or other mounted media you have to apply the same steps in a reverse order.
First unmount the drive as you normally would for a drive not using any type of encryption:
# umount /tmp/usb-mount-folder
And then close the LUKS volume:
# cryptsetup luksClose name-of-volume
At this point you can confirm that the USB drive is no longer mounted by checking the output of df -h
and unplug your USB drive.
Conclusion
These set of commands are very simple and should be hard to forget, but just in case it does happen again the future, I can come here to check on my notes.