When in nautilus
or caja
I click on the icon of an encrypted disk and enter my password, the underlying block device gets mapped to /dev/mapper/luks-$UUID
and it gets mounted at/media/$USER/$DISK
, no root password required.
Is there a way to invoke this process from the command line, without GUI,
including obviating sudo and having the mountpoint able to get unmounted again from GUI.
Linux – Mounting LUKS from the command line
cajagvfslinuxluksmount
Best Answer
I don't know of a single-command way to do this. The GUI programs are doing a fair bit of interrogation of the disk to take the "right" approach and you'll need to do some of that work yourself. You don't need sudo, though, and I think the resulting sequence of events is relatively painless.
The Short Answer
Use
udisksctl
from theudisks2
package:Your user account will need to be appropriately authorized in order for the above to work. On Debian and Ubuntu, that means adding your account to the
plugdev
group.When you're done with the disk:
How to Set Things Up
Here's how you can set things up (via the command line) to make the process of using the disk as painless as possible. I'll assume you want to use the entirety of the USB drive as a single filesystem. Other configurations will require modifications to the instructions. Caveat on variations: I haven't found a way to use LVM in the encrypted container that will allow an unprivileged account to disconnect everything. (I don't see a way to deactivate a volume group via
udisksctl
.)For purposes of illustration, we'll say that the disk is
/dev/sda
. You'll need a name for the filesystem to make it easier to reference later. I'll use "example
".Partition the Disk
Run
sudo parted /dev/sda
and run the following commands:The
mkpart
command will probably prompt you to adjust the parameters slightly. You should be okay accepting its recommended numbers.The partition will now be available via
/dev/disk/by-partlabel/example-part
.Create and Mount the LUKS Partition
Go through the prompts.
The encrypted device is now available at
/dev/mapper/example-unlocked
. This is not going to be a permanent thing; it's just for the setup process.Create Your Filesystem
Let's assume that the filesystem you're using is XFS. Pretty much any other traditional filesystem will work the same way. The important thing is to add a label that you can reference later:
The filesystem's block device can now be accessed via
/dev/disk/by-label/example
.Set Filesystem Permissions
By default, the filesystem will be only accessible by root. In most cases, you probably want the files to be accessible by your user account. Assuming your account name is "
user
":Close Everything Down
Use Your Filesystem
This is what you'll do regularly. After plugging in the USB drive,
If your user account is "
user
", the filesystem will now be mounted at/media/user/example
.To unmount the filesystem:
Now you can disconnect the USB drive.