You can protect your data by encrypting a partition in Linux.
With Linux, you actually have a number of ways to add encryption to your servers and desktops. One of the more secure routes is encrypting an entire partition (as opposed to folder-level encryption). By encrypting an entire partition in Linux, you no longer have to worry that you might have left a crucial directory unencrypted.
Before we get to the encryption in Linux, we have to install the tool to take care of the process. For this demonstration we will be using Ubuntu, to encrypt the partition sdb1.
Open up a terminal window and issue the command:
sudo apt-get install cryptsetup-bin
2. Encrypting Your Partition
Before we encrypt, let’s ensure we have the right partition. From the terminal window, issue the command sudo lsblk. This command will list all block devices attached to the machine.
Before you can encrypt the partition, it must be unmounted. You can do this from your file manager or from the command line.
For example, /dev/sda1 is mounted to the /data directory. To unmount that from the command line, you would issue:
sudo umount /data
Now that we are certain the partition we want to encrypt is sda1 (and it isn’t mounted), issue the command:
sudo cryptsetup luksFormat /dev/sda1
You will see a warning (see below) and asked to type YES to continue.
This will overwrite data on /dev/sda1 irrevocably.
Are you sure? (Type uppercase yes): YES
Next, you’ll be asked to type and verify a passphrase for the encryption. Make it a strong password or passphrase.
The /dev/sda1 partition is now encrypted. You can check on that by opening up your file manager. If you see the tiny lock icon associated with the drive, you know the partition has been encrypted.
3. Mounting the Partition
In most cases, the best way to mount the partition is from the command line:
- Issue the command sudo cryptsetup luksOpen /dev/sda1/ crypthome
- Create a directory to mount the partition with the command sudo mkdir /mnt/crypthome
- Mount the encrypted partition to the new directory with the command sudo mount /dev/mapper/crypthome /mnt/crypthome
You will probably have to adjust the permissions of the /mnt/crypthome directory, depending upon your needs. Otherwise, your encrypted partition in Linux is now available.
If your information security policies require encryption on your devices, these instructions will help you meet that responsibility.
Encryption is a basic way to make sure your data, or your company’s data, stays safe.
Does your company have an encryption policy?