Encrypt partition with dm-crypt

Ever wnated to have your external disk or USB stick encrypted? This is a way to get there on a Debian-based system using dm-crypt and LUKS.

First, make sure dm-crypt module is loaded (see if /dev/mapper/ is present), and if not, load the module:

Now you can use cryptsetup to encrypt your device (you’ll be asked for a password):

After this step, you can open the encrypted disk.

The disk is not ready yet, we need to format it first, just as if we connected an empty device. In theis example, I’ll format it using ext3 file system.

Now you can finally mount and access your disk.

When you’re done and want to unplug the device, you unmount it the usual way:

and then use LUKS to close the encrypted connection:

Now you can remove the device.

Tagged with: ,