Home Blog Page 1078

How to Encrypt a Linux File System with DM-Crypt

Editor’s Note: File system as two words refers to the layout of your directories, which includes things like the /dev directory that represent different hardware devices and don’t actually refer to files on your disk drive. And “filesystem” refers to the software that manages the files and directories.

Encryption fig-1One common question we get from Linux.com readers is about how to implement a file system encryption method for Linux. Before we dive into this, I want to make two points:

First, it’s hard to find decent information on the web about this. So I’m going to point you to a couple of really good resources I managed to find.

Second, it’s important to understand the technical details of the problem. And that’s what I’m going to address here, after which I’ll give you some pointers on how to accomplish the encryption, and then point you to the other resources.

People from time to time say they want to encrypt their data, but there’s a fundamental part missing in what they’re asking: What exactly do they want to encrypt? Do they want to encrypt their data from within a software package, and then store that data to the hard drive in a single file? For example, would they like LibreOffice to create an entire .odt word processing document, and encrypt it, and then write the encrypted results to the file system as a single file, as in the following figure? Or would they like Linux to take care of the encryption itself at the file system level?

In the case of Linux taking care of it, LibreOffice would have to do nothing other than read and write the files as it currently does. Linux would encrypt the file before actually writing it to the disk, and decrypt it after reading it back. This is the approach I’m taking here, but for this there are many other questions you need to ask. And to ask the right questions, you need to understand how block storage works. Let’s look at that first.

Block Level Storage

When an operating system works with a local drive, the operating system uses filesystem software to format the drive, and then read and write individual sectors. When you save a file, the filesystem software figures out the sectors to write to. When you read a file, the filesystem figures out which sectors the data is on, and then reads those sectors and reconstructs the file for you. To manage the files, the filesystem uses different types of indexes that it also stores on the disk. Different filesystems use different means to organize the data, and also include various security mechanisms; the end result is different file systems such as ext4 and NTFS.

Low-Level Details

Encryption fig-2Now that we’re clear on how block-level devices work, consider this: The operating system uses its filesystem software to write the sectors of data to the drive. The filesystem software determines where to write the sectors of data and how to organize them, including the creation of metadata that describes the filenames and how they’re organized, and so on. But in order for the filesystem software to perform the actual read and writes to the drive, there needs to be present a device driver that does the actual controlling of the device itself, as shown in the left side of the next figure. (The drivers are represented in your file system hierarchy within the /dev directory.)

Right at this point–the spot from the filesystem software to the device driver–there’s a choice to be made in encryption: Do you want the filesystem software to do the encrypting before writing the data? Or, how about we effectively wedge a piece of software in between the filesystem software and the device driver? This way, the filesystem will operate as it normally does, but when it tries to access the device, its calls instead will be handled by encryption software, as shown on the right side of the following figure. This how we’re going to do it for this article. But first let’s talk about a few more issues.

(Incidentally, if you want to see how device drivers exist in the /dev directory of your Linux system, check out this article. It covers programming, but if you aren’t a programmer, click to page 2, and scroll down to the section labeled Hello, World! Using /dev/hello_world and read the first paragraph for a glorious explanation.)

If you want to encrypt an entire partition, you might consider encrypting the entire drive. However, there’s one little problem there. If the computer boots from the drive, the drive needs a small portion dedicated to the bootup code. This bootup code is machine code that the computer reads in and executes to boot the computer. If the entire hard drive is encrypted, including this data, the computer would need some way to decrypt the data. But the computer doesn’t have a file system loaded yet, so it can’t read a program that decrypts it. See where this is going? The decryption code would need to be in the BIOS itself. But most computers don’t have such code. And that means the boot record really can’t be encrypted (although people have discussed various ways around this problem such as putting the bootup on a removable USB drive, as well as how to solve other technical issues).

Remote Drives

If your drive is remote, there are ways you can access the data; this is important in understanding what type of encryption is available to you. The two ways are:

  • Block-level storage just like with local drives, whereby your filesystem software can read and write directly to the sectors on the remote disk

  • File-level storage whereby your operating system sends files to a remote server, which has its own operating system and filesystem software; this remote server in turns writes the files to its disk.

With file-level storage, you don’t have many choices regarding encryption. If you want to encrypt the data, you need to encrypt it in your application before sending it on to the remote server for storage.

But with block-level remote storage you do have options. For example, if you’re using a cloud hosting service whereby you can attach different volumes to a server you allocated, you’re usually using block-level storage. The volumes aren’t necessarily attached physically to your hosted server; yet, the server can access them as if they are, and format the volume and read and write individual sectors just as if the drive is mounted locally. What this means is with block-level remote storage you can perform encryption at the file-system level just as you might on your local computer and local drive.

The software

Now we know what we want to accomplish; the question is, how do you do it? It turns out Linux has a software package built in that uses the method I explained earlier of wedging software in between the filesystem software and the device drivers. The software is called dm-crypt. And dm-crypt encrypts the data and writes it onto the storage device (by way of the device driver) using a storage format called LUKS.

LUKS (Linux Unified Key Setup) is the format used on the drive itself, and is essentially used in place of a file system such as ext4. The dm-crypt system sits between the filesystem software; the filesystem software reads and writes ext4, and the ext4 data gets pushed through dm-crypt which then stores the data in LUKS format on the drive. Thus, you can effectively have a file system such as ext4 or NTFS sitting “on top of” the encrypted LUKS format.

Note that dm-crypt is the name of the subsystem, and that you use various tools to work with it. There is no single command called dm-crypt. There are some programs you can use to manage dm-crypt: 

Note that dm-crypt is the name of the subsystem, and that you use various tools to work with it. There is no single command called dm-crypt. There are some programs you can use to manage dm-crypt:

Other Features

One cool thing about the dm-crypt system is that it doesn’t have to work directly with a disk driver. Instead, it can save all the data into a single file instead of using LUKS and a whole disk partition. What that means is you can have dm-crypt create a single file within which you could create an entire file system. Then you can mount that single file as a separate drive, and then access it from any software just like you would any other drive.

Cloud Drives

Because some cloud providers (such as Amazon Web Services) give you full roo access to the block devices connected to your servers, you can make use of dm-crypt; you can format a block device with the LUKS format, and then prepare it for your dm-crypt system; then you can format it all with an ext4 file system. The end result is a fully encrypted drive living in the cloud, one that you manage yourself. Want to try it? Here’s a tutorial on doing it using the cryptsetup program.

Some other cloud providers don’t give you direct access to the block device as AWS does. For example, Digital Ocean does not give you direct access; but you can still create a file and set up dm-crypt to use that file, and then create what they call a “container” within the file that represents the file system. In fact, the process of this is the same way you would accomplish creating an encrypted container file on your own local machine. And here’s Digital Ocean’s tutorial on creating a dm-crypt LUKS container file. Notice in this tutorial that just like with the block device, you create an entire file system (such as ext4) but in this case that file system lives inside the container file.

Local Drives

And that brings us to how to accomplish all this locally. The tutorial above for creating an encrypted drive on Amazon is the same steps for creating it locally on one of your own hard drives. But here’s another tutorial that gives step-by-step instructions for doing it locally on your own hard drive, also using cryptsetup.

If you want to create a local container drive that contains an entire encrypted file system, just follow the steps in the Digital Ocean tutorial above.

Or if you want to use the other program, cryptmount, to encrypt an entire partition or create a container file, follow this tutorial; the author, Carla Schroder, knows her stuff and provides some good steps.

Conclusion

That’s about it. The important thing about knowing how to encrypt is to fully understand first what you’re really trying to accomplish – have an application encrypt and decrypt its data, have the operating system handle the encryption; and whether to encrypt an entire partition or just individual files; and whether to create a container to hold the encrypted files. Then you can follow the steps on the tutorials I linked to here and get the job done right.

Linux Kernel At 19.5 Million Lines Of Code, Continues Rising

With Linux 4.1 having been released this week and being mid-way through 2015, here’s some Git development statistics for the newest kernel code…

Read more at Phoronix

Why the result of Top is not consistent with Psutil

Dear all,

I have written a script and measure the CPU utlization of the script using psutil inside it. When I compare the result with Top, there was a big differece even thought I used -d to minimize the delay? Why ?

Thank you!

Best,

Tom

Announcing Our First SysAdmin Linux Certification Workshop at LinuxCon

Are you looking for a way to jumpstart your IT career or move mid-career to managing Linux systems? The 2015 Linux Jobs Report showed that certification is a great way to do this, with 44 percent of managers reporting they are more likely to hire someone with a certification. That’s one reason we created our Linux Foundation Certified SysAdmin program. If you have Linux skills, show it off with a convenient, neutral exam that has the backing of the Linux Foundation.

This year for the first time we’ll host an in person SysAdmin certification prep workshop the day prior to LinuxCon in Seattle, Sunday, August 16, 2015. It’s only $69 which is a huge bargain on its own, but as an added bonus includes $100 towards your certification exam. And if you’re attending LinuxCon, CloudOpen and ContainerCon, the cost of the workshop is included in your registration.

Taught by Dr. Jerry Cooperstein, The Linux Foundation’s Training Program Director who developed the Essentials of System Administration course, this workshop will provide the opportunity to dig into topics relevant to taking the exam and to get your questions answered live. Jerry is an amazing Linux talent and teacher so this is a wonderful chance to learn from the best at a very small price.

Since the launch of the Linux Foundation Certified System Administrator exam last August, we have worked to make exam prep materials and courses as accessible as possible. This workshop builds on those initiatives, such as the release of our certification exam prep guide, the bundled Essentials of System Administration course and certification exam offered at an affordable price point, and allowing those who do not pass the exam on their first attempt to retake it for free. But this is a chance to visit Seattle, meet many of us in person and learn a lot about Linux, containers and the newest cloud technologies.

We believe this is a great opportunity to take the first step toward an outstanding career in Linux. Register today, and we’ll see you in Seattle!

 

Linux 4.2 Power Management Update Yields More ACPI 6 Changes

Open-source developers for a while have been working on ACPI 6 support for Linux with 64-bit ARM support, ACPI 6 NV-DIMM support, and other functionality. With the Linux 4.2 kernel that’s now in-development, more ACPI 6 code will be landing…

Read more at Phoronix

Beautiful Material Design-Inspired Papyros Linux Distro Getting Closer to Release

Papyros is getting closer to working release, and the developers are putting the final touches. We’ll soon be able to play with the new distro, even if it’s going to be just a development version.

The Papyros is a Linux distribution that follows the guidelines from Material Design, which have been implemented in the latest Android 5.x Lollipop from Google. There are already a number of themes out there that have been inspired by Material Design, but no one has gone through … (read more)

Fedora 23 Is Planning For Unicode 8.0

With Unicode 8.0 having been released last week, Fedora developers are planning on incorporating it into Fedora 23…

Read more at Phoronix

Buick and GMC join GM’s list of CarPlay and Android Auto brands

GM has been moving quickly to announce wide-ranging support for Apple’s CarPlay and Google’sAndroid Auto in recent weeks, and the automaker can add two more of its brands to the mix: Buick and GMC, both of which will start adding compatibility this year. CarPlay comes first, hitting the 2016 Buick LaCrosse and Regal alongside GMC’s 2016 Canyon, Yukon and Sierra; Android Auto will follow later. If that approach sounds familiar, it should — it’s the same one that GM is employing with Chevrolet and Cadillac, both of which have already made their connected car announcements.

 

Continue reading…

Read more at The Verge

Linux 4.2 Works On More Scheduler Improvements

Alongside his many other pull requests, Ingo Molnar sent in the scheduler changes on Monday for the Linux 4.2 kernel…

Read more at Phoronix

A Template for Starting Project Documentation

Image of typewriter keys

Let’s say you’ve created a program or launched an open source project, and now you have people’s attention. They start to ask more and more questions, taking more and more of your precious developer time to answer. They fill your mailbox, sometimes even spam your IRC channel, often repeating the same questions. You know that you need to provide something in writing to help your users. But where should you start? What tools can you use? What output format do you choose? What subjects must you cover?

read more

Read more at OpenSource.com