Encrypting partitions with cryptsetup
Encrypting Existing Partitions
Cryptsetup has more – many more – options, but these should be enough to show you how to start using encrypted partitions, especially if you only want a vault.
Encrypting an existing directory, such as /home
, is more complicated but is as much a matter of organization as of learning more commands. To encrypt an existing partition, follow these steps:
1. Copy all the files to another partition. As described above, you might want to create a partition of at least equal size.
2. Set up and map the encrypted partition. For convenience, use its existing directory name, such as /home
.
3. Create a passkey file in the /root
directory so that the device automounts at boot with:
touch /root/[MAPPED DEVICE]_passkey && chmod 600 /root/[MAPPED DEVICE]_passkey
4. Map the device with:
cryptsetup luksAddKey /dev/[DEVICE] /root/freeagent_passkey
5. Create a filesystem on the encrypted device.
6. Add the following line to /etc/fstab
:
/dev/mapper/[MAPPED-NAME] [MOUNT POINT]] ext4_netdev 1 1
7. Add the following entry to /etc/crypttab
:
[MAPPED NAME]/dv/ [DEVICE]/[MOUNT POINT]
8. In the case of /home
, copy the hidden files to the encrypted partition, then test by rebooting. If no problems appear, copy the rest of the files to the encrypted version of /home/
.
Encryption, as you can see, is more complicated than checking a box when you tackle it hands-on. However, the amount of control that do-it-yourself encryption can bring will make it worth the effort, because you are getting exactly what you want.
Bruce Byfield
Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest coast art. You can read more of his work at http://brucebyfield.wordpress.com
Infos
- cryptsetup man page: http://linux.die.net/man/8/cryptsetup
- ECryptfs: https://en.wikipedia.org/wiki/ECryptfs
- EncFS: http://www.arg0.net/#!encfs/c1awt
- Loop-AES: http://sourceforge.net/projects/loop-aes/
- TrueCrypt: https://en.wikipedia.org/wiki/TrueCrypt
- dm-crypt: https://code.google.com/p/cryptsetup/wiki/DMCrypt
- Linux Unified Key Setup: https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup
- cryptsetup download: https://code.google.com/p/cryptsetup/wiki/Downloads?tm=2
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.