Menu
Is free
check in
the main  /  Navigators / Encryption data in Linux. Disk Encryption in Linux Disk Encryption in Linux Debian

Encryption data in Linux. Disk Encryption in Linux Disk Encryption in Linux Debian

Introduction

Storage of data in an encrypted form is an excellent way to protect the information so that it does not get to the attacker. For the protection of intellectual property, production secrets or personal information is developed cryptographic systems. They can be performed in various forms, offer different levels of functionality and contain any number of options to approach a wide range of operating shells and media. Today, the number of modern cryptographic methods, algorithms and solutions are much larger than before. Yes, and the quality of development is much better. Moreover, there are many workable solutions on the market based on open Code.What allows you to achieve a good level of protection without spending large amounts of money.

In December 2005, the Ponmontime Institute conducted among various specialists in the field of information security poll regarding encryption and data protection. Among the 6298 surveyed only 4 percent of respondents used encryption across the enterprise. From the same survey, three main reasons for persistent opposition to official encryption rules were revealed:

  • 69% of respondents mentioned performance problems;
  • 44% of respondents mentioned difficulties with the implementation;
  • 25% of respondents spoke about the high price of the implementation of cryptographic algorithms.

In many countries, organizations are exposed to multiple pressure levers to increase the "transparency" of their work. But, on the other hand, they are responsible for the nonstraction of the safety of confidential information. So it was, in particular, in the case of DSW's shoe stores in the USA).

The US Federal Trade Commission has put forward a lawsuit against DSW, in which it was stated on the insecurity of the proper level of information protection and non-adequacy of proper measures to build adequate systems for restricting access to these data, as well as unsatisfactory protection network connections Between the shop I. office computers. In the case of DSW, about 1.4 million credit cards and about 96 thousand check accounts were potentially available to criminals. And before the agreements between the company and FTK were achieved, these accounts had already managed to illegally use.

Nowadays, software and engineering data encryption solutions are available as ever. A USB key, which is getting the day of day, is increasingly used instead of smart cards. The latter, in turn, also often can be found, because most laptops contain smart card reader.

Consumers are increasingly beginning to think about the dangers relating to theft of personal information, data about the owner, credit card numbers. And these concerns are only warmed by messages about mass sales of stolen information of this kind of institutions that are entrusted with such valuable data.

Consumers also begin to realize that it is important to protect personal information not only on the Internet, but also outside the network. In the end, unwanted access to your data is not always happening through the network. This issue is especially relevant for those whose unprotected laptops can get either in the hands of the service personnel to change the configuration, or to the service for repair.

Technical questions encryption

Encryption functions are needed to all modern multiplayer computer systemswhere data, processes and user information are logically divided. To determine the authenticity of the user in a similar system, logins and passwords are combined and compared with the hash systems already available in the system (either the HASH is used to decrypt the session key, which is then checked for validity). In order to prevent unauthorized viewing of personal information inside encrypted containers, individual files or entire sections can be stored. BUT network protocols, for example, SSL \\ TLS and IPsec, allow, if necessary, strengthen cryptographic protection various devices (/ dev / random, / dev / urandom, etc.) with the help of modular algorithms operating with the core operating system.

The task of any disk encryption technology is to protect against unwanted access For personal information and in a decrease in damage from the loss of intellectual property as a result of illegal access or theft of the physical device. Operational linux system With the version of the core 2.6.4 introduced an improved cryptographic infrastructure that simply and reliably protects personal data at many levels software. There are as entire storage standards in encrypted form at a low level, like Linux Unified Key Setup (LUKS) and implementations at the user-level level, for example, EncFS and Cryptofs file systems, which, in turn, are based on Fast Userspace File System ( FUSE) under Linux. Of course, any cryptographic system is stable to crack as much as its passwords and access keys. There are three main levels on which encryption technologies are used:

  • file level I. file System (Patch Encryption, Container with Files);
  • low block level (container with file system);
  • iron level (specialized cryptographic devices).

Encryption at the file level is a very easy way to use usually for sharing files. Encryption is used from the case of the case that it is convenient for sending a reasonable number of files. For multiplayer file systems, the problem of keys management occurs, since folders and files of different users are encrypted with different keys. Of course, you can use one key, but then we get a technology that resembles disk encryption. As always, the user is responsible for choosing the most reliable password.

More advanced cryptographic applications operate at the file system level, tracking files at the time of creation, recording or modifications. This method provides better defense Personal information in any way of using it, it is good and with a large number of files. In addition, it is not necessary to take care of applications that do not know how to encrypt files separately.

Some cryptographic technologies are free and included in many distributions. By the way, latest versions Windows is equipped with a special file system with Encrypted File System (EFS) encryption support. Fedora supports a number of encryption options, including LUKS (you can enable LUKS support and under Windows if you use FAT or FAT32 file systems and the FreeOtfe application). And in additional Extras packages are available FUSE and ENCFS. Cryptofs can also be installed by downloading from official site. .

The FUSE infrastructure consists of a loaded module of the kernel and the userspace library, which serves as a basis for the Cryptofs file system and for Encrypted File System (EncFS). According to its structure, FUSE does not affect the source code of the core and at the same time provides high flexibility to implement many interesting additions, such as the SECURE SHELL FILE SYSTEM (SSHFS) file system.

Cryptofs stores encrypted data in the usual structure of the directory separated into two main parts: text information (List of files, folders, archives) and actually encrypted data. You can re-mount the encrypted directory using the key. When using Cryptofs do not need special privileges, the setting is also not difficult.

ENCFS file system is also a userspace-implement based on the FUSE library, providing protection against theft of information and operating on the principle of patching encryption. She inherited its structure from early versions, but with improvements in both form and functions. The ENCFS file system can be dynamically expanded to satisfy the increasing user requirements. Files can be encrypted in various parameters (for example, when changing the content, by attributes, etc.). In fact, the underlying storage for ENCFS can be anything: from the ISO image to a network partition or even a distributed file system.

Both file systems work through the end-to-end principle, and they can be used on top of other file systems and logical abstractions, for example, on top of a log or extended file system, which can be distributed across multiple physical media using a logical partition manager (LVM). The following illustration schematically shows how this file system works: in this diagram, the visible directory is indicated / MOUNT (the level of unencrypted ENCFS data).

Userspace-overlay showing the interaction of FUSE and ENCFS.

Under the level of the file system abstraction, there are schemes of low-level (block) encryption, similar to those used in LUKS. Schemes of this type work only on the disc units, not paying attention to the abstraction of the file system of higher levels. Such schemes can be used for paging files for various containers or even for integer physical media, including the full encryption of the root section.


LUKS works without accurate knowledge of the file system format.

LUKS is designed in accordance with Trusted Key Setup # 1 (TKS1) and compatible with Windows, if you use any common file system format (FAT / FAT32). The system is well suited for mobile users, Supports the release and review of the keys GNU Privacy Guard (GPG) and is absolutely free. LUKS is capable of much more than any other implementation described in this article. Moreover, LUKS supports a large number of solutions for creating and managing devices with LUKS encryption.

The Cryptofs file system only receives a password, while the media encrypted with LUKS works with any PGP (Pretty Good Privacy) keys with any password password. Encfs also uses a password to protect files, but it opens the key stored in the appropriate root directory.

Differences between the implementations on low and userspace-levels are best noticeable on practical tests. At a low level, data can be "transparent" transferred to the file system, which manages recording and reading operations is much more efficient.

Test configuration

Our test platform has become the Dell Latitude C610 laptop, a little outdated, but still a smart representative of the 2002 sample technologies. When nutrition from the battery, C610 reduces the frequency of the processor to 733 MHz. Therefore, during testing, we did not turn off the laptop from the outlet. The following table shows the laptop configuration

Test results were obtained using the EXT3 file system under Linux. Perhaps ext3 in comparison with other log file systems is not the most productive. But experiments S. thin set System format, block size, storage parameters, etc. Are not tasks of our testing, because they do not meet the criteria for easy setup and configuration. Recall that the purpose of the article was to show how the cryptographic solutions under Linux allow you to simply, effectively and cheaply create protected data warehouses.

Installation

LUKS, FUSE and ENCFS are available in the Fedora distribution, so that additional efforts do not need. But Cryptofs will have to download separately.

Cryptofs compilation from the source code is quite simple. Unpack the archive, run the configuration script in the final directory, then run Make, as shown in the illustration. The configuration file contains four parameters: Encryption Cipher, Message Profile Algorithm (Message Digest Algorithm), Block Size (Encryption Salt Count).


Cryptofs installation process is simple.

The setting consists of specifying paths of the initial and final directories (for encrypted and unencrypted data). Then you can run the CRYPTOFS command, as shown in the following figure.


CRYPTOFS setup.

Then you can run the Mount command, after which you can see the mounted partition.

First make sure to download the FUSE kernel module (ModProbe Fuse). Encfs simplifies the process of creating an encrypted container, as can be seen in the following illustration.


If you lower the process of setting the keys (which is specific for each situation), then LUKS can be easily configured as shown below.


Tests and performance analysis

Differences in performance between the "native" installation and installation in an environment encrypted LUKS are quite insignificant. Especially taking into account the noticeable difference in userspace solutions. For an alternative assessment of the performance of encrypted file systems, we used iozone. For tests, recordings from 4 KB to 16 MB are used, the file size changes from 64 KB to 512 MB, and the result is specified in the Krib / s.

Conclusion

At least, where LUKS is used, you can not think about performance. Although, of course, some loss of performance is caused by "transparent" data encryption. The LUKS system is easy and easy to install, and you can use it both in Linux and under Windows.

Corporate users will probably have to face restrictions related to the company's policies. Often they prohibit solutions based on an open source code or prohibit some implementations. In addition, sometimes you have to take into account the import / export restrictions on encryption technologies concerning the durability of the code, or the IT department requires telephone support from the solution provider, which allows you to forget about LUKS, ENCFS and CRYPTOFS. In any case, LUKS is an excellent solution if such problems do not bother you. A good option For small businesses or for home users.

But it should be remembered that data encryption is not a panacea. Since encryption is transparent, any Trojan program operating on behalf of the user can access encrypted data.

Opinion opinion

Cryptofs and Encfs - Userspace-implementations. As we have explained earlier, they differ simplicity of design and implementation, but it has to pay for performance and opportunities. This is especially obvious when compared with LUKS. It not only works significantly faster, but also supports one or more PGP keys and can be used on the whole section.

Userspace containers are important, first of all, for users who wish to protect personal information in a multiplayer environment. And who needs to protect their data so that even the administrator cannot access hardware or software resources. In addition to performance and inter-platform support, LUKS is perfectly integrated with GNOME and PGP key control systems. And the ease of everyday use of encrypted LUKS sections is simply impressive. By the way, EncFS supports Pluggable Authentication Module (PAM) under Linux in the respective environments.

Keep in mind, the author of this labor tells about the methods of encryption sections of the disc, which uses himself, with.

Linux

This manual uses Linux Dm-Crypt (device Mapper.) On the nucleus 2.6 . We will encrypt the section / dev / sdc1, it can be any partition, disk, USB or file created by losetup.. Here we will use / Dev / Loop0, look. Device Mapper. uses a label to identify a partition in this example sDC1But it can be any other line.

Encryption of disk partitions using LUKS

LUKS. from dm-Crypt. It is very convenient to encrypt disk partitions, it allows you to have several passwords for one partition as well as easily change them. What would you check any use available LUKS., type: cryptSetup --help.If about LUKS. Nothing appeared, read below. " dm-Crypt without LUKS"For a start, create a section, if necessary fDISK / DEV / SDC.

How to create an encrypted section

# dd if \u003d / dev / urandom of \u003d / dev / sdc1 # Optional. Only for paranoikov # CryptSetup -y LuksFormat / Dev / SDC1 # It will destroy all the data on sDC1 # CryptSetup Luksopen / Dev / SDC1 SDC1 # MKFS.EXT3 / DEV / MAPPER / SDC1 # Will be created file system eXT3 # MOUNT -T EXT3 / DEV / MAPPER / SDC1 / MNT # umount / MNT # CryptSetup Luksclose SDC1
Mock
# CryptSetup Luksopen / Dev / SDC1 SDC1 # MOUNT -T EXT3 / DEV / MAPPER / SDC1 / MNT
Unmount
# Umount / MNT # Cryptsetup Luksclose SDC1

dm-Crypt without LUKS

# CryptSetup -y Create SDC1 / DEV / SDC1 # Or any other section, type / Dev / Loop0 # Dmsetup Ls. # Check, will show: sDC1 (254, 0) # MKFS.EXT3 / DEV / MAPPER / SDC1 # Only if done for the first time! # MOUNT -T EXT3 / DEV / MAPPER / SDC1 / MNT # umount / MNT / # Cryptsetup Remove SDC1 # Disconnect the encrypted section Make the same thing, (without creating FS), whatever it is to reconnect the section. When entering an incorrect password, the MOUNT command will not be executed. In this case, simply delete the display. sDC1 (cryptSetup Remove SDC1) And create a new one.

FreeBSD.

A couple of popular modules for encryption disks in, it is gBDE and geli.. Geli. more rapid because uses hardware acceleration. See FreeBSD Handbook Chapter 18.6 for a more detailed description. For work, geli. Must be loaded as the kernel module, or built into it at the compilation stage. Options Geom_eli Device Crypto # Or load as kernel module: # Echo "geom_eli_load \u003d" yes "" \u003e\u003e /boot/loader.conf # or kldload geom_eli

Use password and key

The author uses these settings for typical sections encryption, it uses a password and key to encryption " Master Key. - the main key. "Whatever the encrypted section, you will need a password and key /root/ad1.Key. "Master Key."It is stored in the partition and invisible. The following example is typical for a USB or file image.

Create an encrypted section

# DD if \u003d / dev / random of \u003d / root / ad1.key bs \u003d 64 count \u003d 1 # This key encrypts Master Key # GELI INIT -S 4096 -K /ROOT/ad1.key / dev / ad1 # -s 8192 and OK for disks # GELI ATTACH -K /ROOT/ad1.Key / dev / ad1 # Do Creates backup /root/ad1.Key # DD if \u003d / dev / random of \u003d / dev / ad1.eli bs \u003d 1m # optional and takes a lot of time # newfs /dev/ad1.eli # Create File System # MOUNT /DEV/ad1.eli / MNT # Mounting an encrypted partition
ATTACH
# Geli attach -k /root/ad1.key / dev / ad1 # fsck -ny -t ffs /dev/ad1.eli # If there are doubts, check the file system # MOUNT /DEV/ad1.eli / MNT
Detach.
The unmounting procedure is performed automatically when it is turned off. # umount / mnt # geli detach /dev/ad1.eli
/ etc / fstab
Mounting the encrypted partition can be configured through / etc / fstab. The password will be requested when loading. # grep geli /etc/rc.conf geli_devices \u003d "ad1" geli_ad1_flags \u003d "- k /root/ad1.key" # grep geli / etc / fstab /dev/ad1.eli / home / private UFS RW 0 0

Only by password

This is more suitable way To encrypt the flash drive or image based on the file, only password is requested. In this case, you do not need to worry about key files. The procedure resembles the above described, except for creating key files. Enchant the size of 1 GB, created from the file / CryptedFile.. # dd if \u003d / dev / zero of \u003d / cryptedfile bs \u003d 1m count \u003d 1000 # Create 1GB file # mdconfig -at vnode -f / cryptedfile # geli init / dev / md0 # Encryp only by password # geli attach / dev / md0 # newfs -u -m 0 /dev/md0.eli # mount /dev/md0.eli / mnt # umount /dev/md0.eli # geli detach md0.eli Now this image can be mapped to Other car, just entering the password. # MDConfig -at vnode -f / cryptedfile # geli attach / dev / md0 # mount /dev/md0.eli / mnt

Security and confidentiality are very important for those who store important data on the computer. Your home computer is safe, but with a laptop or other portable devices, the situation varies very much. If you wear your laptop with you almost everywhere and unauthorized persons can have access, the question arises - how to protect your data from someone else's intervention. It is from physical attacks where every wishes can try to get data from a USB drive or a laptop hard disk simply by picking a device or in case of a laptop, pulling the hard disk and connecting it to another operating system.

Many enterprises and even simple users Use disk encryption in Linux To protect confidential information, such as: Customer information, files, contact information and much more. In the Linux operating system, several cryptographic methods are supported to protect partitions, individual directories or a fully all hard disk. All data, in any of these methods, are automatically encrypted and decrypted on the fly.

Encryption at the file system level:

  • 1. Ecryptfs. - This is a cryptographic file system Linux. It stores cryptographic metadata for each file in separate fileThus, the files can be copied between computers. The file will be successfully deciphered if you have a key. This solution is widely used to implement an encrypted home directory, for example, in Ubuntu. Also chromeos transparently embeds these algorithms when used network devices For data storage (NAS).
  • 2. Encfs. - Provides an encrypted file system in the user space. It works without any additional privileges and uses the FUSE library and the kernel module to provide the file system interface. ENCFS is free software and it extends under the GPL license.

Block encryption at the device level:

  • Loop-Aes. - Fast and transparent file system, as well as a package for encrypting a paging section in Linux. The source code of the program has not changed a long time. It works with kernels 4.x, 3.x, 2.2, 2.0.
  • TrueCrypt. - This is a free open source solution for encryption disk in Windows 7 / Vista / XP / Mac OS X operating systems, as well as in Linux.
  • dm-Crypt + Luks - DM-Crypt is a transparent subsystem for disk encryption in the kernel 2.6 and later versions. Supported encryption of entire disks, removable media, partitions, RAID volumes, software, logical volumes and files.

In this manual, we will look at the encryption of the hard disk on Linux using the Linux Unified Key Setup-On-Disk-Format (LUKS) algorithm.

How does LUKS work?

LUKS (Linux Unified Key Setup - Block Encryption Protocol. But we ran down far to understand how it works, you need to have downloaded to deal with other technologies used in this method.

To perform the Linux disk encryption, the DM-Crypt kernel module is used. This module allows you to create a virtual block device in the / Dev / Mapper directory with a transparent file system and a user with encryption. In fact, all the data lie on the encrypted physical section. If the user tries to write data to a virtual device, they are encrypted on the fly and recorded to the disk, when reading from a virtual device, a reverse operation is performed - the data are decrypted from the physical disk and transmitted to open video through virtual disk user. Usually, the AES method is used for encryption, because most of the modern processors are optimized under it. It is important to note that you can encrypt not only sections and discs, but also ordinary files by creating a file system in them and connecting as a LOOP device.

LUKS algorithm determine what actions and in what order will be performed while working with encrypted media. To work with LUKS and the DM-CRYPT module use the CRYPTSETUP utility. We will look at it further.

Utility CryptSetup.

The CryptSetUp utility will make it easier to make it easier to encrypt the Linux section using the DM-CRYPT module. Let's install it first.

In Debian or Ubuntu, use such a command for this:

aPT-Get Install Cryptsetup

In distributions based on Red Hat, it will look like this:

yum Install CryptSetup-Luks

The start-up syntax of the command:

$ CRYPTSETUP Options Operation Operations Operations

Consider the basic operations that can be done using this utility:

  • luksformat. - Create an encrypted section LUKS Linux
  • luksopen. - Connect the virtual device (need key)
  • luksclose - close the virtual device LUKS Linux
  • luksaddkey. - add encryption key
  • luksremoveKey - Delete encryption key
  • luksuuid - Show UUID section
  • luksdump - Create a backup of LUKS headers

Operation parameters depend on the operation itself, it is usually either a physical device with which you need to perform an action or virtual or both. Not everything is not clear, but in practice, I think you will deal with everything.

Linux disk encryption

The theory is passed, all tools are ready. Now consider encryption of the Linux section. Let us turn to the hard disk setting. Please note that it will delete all the data from the disk or partition you are going to encrypt. So if there are important data, it is better to copy them to a more reliable place.

Creating a section

In this example, we will encrypt the / dev / sda6 section, but instead you can use a whole hard disk or just one file filled with zeros. Create an encrypted section:

cryptSetup -y -V LUKSFORMAT / DEV / SDA6

Warning!
========
This Will Overwrite Data On / Dev / SDA6 IRREVOCABLY.

Are you sure? (Type Uppercase YES): Yes
ENTER LUKS PASSPHRASE:
Verify Passphrase:
Command Successful.

This command will initialize the partition, will set the initialization key and password. Specify such a password to not forget later.

Perform such a command To open the newly created section using the DM-CRYPT module in / dev / mapper, you will need to enter a password with which LUKS Linux encryption is performed:

ENTER PASSPHRASE FOR / DEV / SDA6

Now you can see a new virtual device / DEV / MAPPER / Backup2 created using the LUKSFORMAT command:

lS -L / DEV / MAPPER / Backup2

To see the device status, follow:

cryptSetup -v Status Backup2

/ Dev / Mapper / Backup2 is active.
Type: LUKS1.
Cipher: AES-CBC-ESSIV: SHA256
KEYSIZE: 256 BITS
Device: / Dev / SDA6
Offset: 4096 Sectors
Size: 419426304 Sectors
Mode: Read / Write
Command Successful.

And with the following command, you can backup LUKS headers just in case:

cryptSetup LUKSDUMP / DEV / SDA6

Well, you can say the section is ready. And what is the most interesting, now you can use them in the same way as any other regular partition in the / dev directory. It can be formatted using standard utilities, record data on it, change or check the file system and T d. You can not only resize. That is, everything is completely transparent, as mentioned at the beginning of the article.

Formatting section

Let's format the disc to start formatting. For reliability, to erase all the data that was in this place before, rebooting our encrypted section Linux zeros. This will reduce the likelihood of encryption hacking, through an increase in the number of random information. To do this, follow:

dD if \u003d / dev / zero of \u003d / dev / mapper / backup2

Work utility may take several hours to be able to observe the process, use PV:

pV -TPREB / DEV / ZERO | DD OF \u003d / DEV / MAPPER / Backup2 bs \u003d 128m

When the process is completed, we can format the device to any file system. For example, format in ext4:

mKFS.EXT4 / DEV / MAPPER / Backup2

As you can see, all CryptSetup commands apply to the physical partition, while the other commands for working with disks - to our virtual.

Mounting section

Now you can only mount that the created file system:

$ MOUNT / DEV / MAPPER / Backup2 / Backup2

Disable section

Everything works, but how to disable the device and protect the data. To do this, follow:

cryptSetup Luksclose Backup2.

Repeated mount

To get the opportunity to work again with an encrypted section using LUKS Linux, you must open it again:

cryptSetup LUKSOPEN / DEV / SDA6 Backup2

Now we can mount:

mOUNT / DEV / MAPPER / Backup2 / Backup2

Check LUKS File System

Since after opening the partition using LUKS Linux, this section is perceived by the system, like all others, you can simply use the FSCK utility:

sudo umount / Backup2

$ FSCK -VY / DEV / MAPPER / Backup2

$ Mount / Dev / Mapper / Backup2 / Backu2

Change LUKS Password Phrase

Linux disk encryption is performed with a specific password phrase, but you can change it. Even more, you can create up to eight different password phrases. To change by following the following commands. First, make a backup of LUKS headers:

cryptSetup LUKSDUMP / DEV / SDA6

Then create new key:

cryptSetup Luksaddkey / Dev / SDA6

ENTER ANY PASSPHRASE:

ENTER NEW PASSPHRASE FOR KEY SLOT:
Verify Passphrase:

And delete the old:

cryptSetup LuksremoveKey / Dev / SDA6

Now you have to introduce another old password.

conclusions

That's all now you know how to encrypt the section in Linux, as well as understand how it all works. In addition, the encryption of disks in Linux according to the LUKS algorithm opens up ample opportunities for the complete encryption of the installed system.

Pros:

  • LUKS encrypts all block device, and therefore very well suited to protect the contents portable devices, such as cell phones, removable carriers or hard drives laptops.
  • You can use on NAS servers to protect backups.
  • Intel and AMD processors with AES-NI (Advanced Encryption Standard) have a set of commands that can speed up the DM-CRYPT-based encryption process in the Linux kernel starting from 2.6.32.
  • It works including with the paging section, so your laptop can use the sleep mode function, or hibernation is completely safe.

Today, storing important data in the open form has become more dangerous. And not even so much because of the state surveillance (they want - they will find, what to complain, and so) how much because of those who want these data to kidnap. In principle, there are many methods to protect information, but cryptographic means will be described in the article.


Unlike some other operating systems, Linux has many means for cryptographic information protection - from encrypting mail correspondence before encrypting files and block devices. We are interested in encryption at the level of file systems, files and block devices. First you should figure out what the difference is. Encryption at the file system level assumes the presence of a layer between the main file system (unless, of course, the file system itself does not support encryption) and the user.

The advantage of this type of encryption is that the keys for all users are different. The lack of - if you enable file name encryption, the length of the valid name will decrease, in addition, the user can save the file to another disk, which automatically levels the benefit. And one more but - even if name encryption is enabled, temporary labels will remain the same. Encryption block devices occurs at a lower level, under the file system. At the same time, the file system itself, of course, does not know that it is on the encrypted volume.

The advantages of this method are opposite to the shortcomings of the previous one. The lack of the fact that every time you download / mount enter the password. The second lack is that if in the ranktime, the attacker will receive access to the files on the cryptocon
Toiner, all - writing gone. This is exactly what protection against offline attacks. In addition, in the absolute majority of cases of conservation of a cryptocontainer in the cloud, it will have to fill it entirely.

The article will describe the configuration of the following methods of crypto protection:
dm-Crypt / Luks - Creating a cryptocontainer using the Device-Mapper and CryptoAPI kernel;
ecryptfs. - encryption at the file system level;
Encfs. - the same as described above, but does not require loading the kernel modules.

Dm-Crypt / Luks
There are two types of DM-Crypt - Plain and LUKS settings. The difference is that in the case of the use of LUKS at the beginning of the cryptotoma, there are metadata, allowing you to use multiple keys and change them. At the same time, the presence of a similar title in some cases in itself is compromising - however, in most such cases it will be compromising and a high degree of entropy. Setting the PLAIN DM-Crypt with a key file and a password phrase as follows how to configure a combination from a Plain DM-Crypt volume encrypted using a key file, in turn contained in the LUKS container. To begin with, it is necessary to decide exactly how the sections will be placed. There are three main options:
just crypto volume;
First crypto, then on top of it LVM;
First crypto, then RAID, then LVM.

And all sorts of combinations. Let's try the second option. First of all, create LUKS container for storing a key file to use this file with a key phrase. In this case, the likelihood of cryptanalysis volume encrypted using Plain DM-Crypt is reduced:

# DD if \u003d / dev / zero of \u003d / root / key.luks bs \u003d 512 count \u003d 2057

# CryptSetup --align-payload \u003d 1 luksformat /root/key.luks

# CryptSetup Luksopen /root/Key.luks Cryptokey

# DD if \u003d / dev / urandom of \u003d / dev / mapper / cryptokey

The first command prepares the container file, the second this container creates, the third connects, the fourth generates key information. It is worth noting that the -LIGN-payload \u003d 1 option is needed so that the size of LUKS metadata is not 4096 512-byte blocks, but only 2056. Thus, 512 bytes remain on the key information itself.
Then go to the creation of a cryptotoma. At this stage, at will, you can also fill the disk with pseudo-random data to make it difficult to cryptanalysis if it is. Then you can create cryptot. The team for this looks like this (naturally, in other cases identifiers may differ, so you need to be attentive):

# CryptSetup --Cipher \u003d Serpent-XTS-Plain64 --offset \u003d 0 - Key-file \u003d / Dev / Mapper / Cryptokey --Key-size \u003d 512 Open --Type \u003d Plain / Dev / Disk / BY-ID / ATA-VBOX_HardDisk_VB05EADEBE-F25E8D59 CRYPTO0


If necessary, you need to repeat the same command and on other devices for which encryption is required. Then create on LVM cryptotomas and the FS on it:

Create a file / etc / initramfs-tools / hooks / cryptokeys approximately the following content (utility part of the script):

And file / etc / initramfs-tools / scripts / local-top / cryptokeys (service part again
same lowered):

# <...>

modProbe - B DM_CRYPT

while! (/ SBIN / CRYPTSETUP LUKSOPEN / ETC / CRYPTO / KEY. LUKS CRYPTOKEY

/ Dev / Disk / BY - ID / ATA - Vbox_harddisk_vb05eadebe - F25E8D59 Crypto0

&& / Sbin / Cryptsetup Plainopen - Key - File \u003d / DeV / MAPPER / Cryptokey

/ Dev / Disk / BY - ID / ATA - Vbox_harddisk_vbc2414841 - CFECCDE5 Crypto1

&& / Sbin / CryptSetup Luksclose Cryptokey

); do.

echo "Try Again. . . "

done

These two files must be executed. Then create initrd:

# Update-Initramfs -u -k All -V

Upon the next reboot, the password for the LUKS container will be requested. In the case of using Plain DM-Crypt, there is another possibility - a common bottom layer, which allows you to do something like the hidden TrueCrypt volumes. It is easier to give an example:

# CryptSetup --cipher \u003d Serpent-XTS-Plain64 --offset \u003d 0 - size \u003d 2097152 --Shared Open --Type \u003d Plain / Dev / Disk / BY-ID / ATA-VBOX_HardDisk_vbcda8398f-F1F1Deec Crypto

# CryptSetup --cipher \u003d Serpent-XTS-Plain64 --FFSET \u003d 2097152 - Size \u003d 2097152 - Size \u003d 2097152 --Shared Open --Type \u003d Plain / Dev / Disk / BY-ID / ATA-VBOX_HardDisk_VBCDA8398F-F1F1Deec Crypto_Shared

Size and offset are indicated in 512-byte blocks.


Extended LUKS features
Let's see also on the extended use of LUKS containers. These include shifting keys. This is necessary when compromising or creating key change policies. The first step for this will be the creation of a backup copy of the container header. If everyone
Normally, after changing the key, it can be destroyed. We do it, understandable, on an unwitting section:

Finally, add a new key to the system:

Consider and the procedure for restoring LUKS volumes. The easiest option, of course, when there is a copy of the header. In this case, only one command is required to restore:

The longest continuous stitch will be the master key. It must be copied to the file on the non-checked volume and then convert to the binary shape (before it should be ensured that in this file No
String end symbols):

Encfs.
Let's see how to configure EncFS to automatically mount when logging in. To begin with, we will put the necessary packages:

When setting up in an expert mode, a number of questions will be specified: the type of cipher (only AES and BWOFISH), the key size, the block size, how to encrypt file names - block encryption (which completely hides the file name, including length), streaming (which encrypts With the most close length, which is sometimes convenient if the names are too long and when using a block cipher, there is a rather high probability exceeding the maximum length) or there will be no password at all ... at the end password will be requested, it must match the entry used, otherwise auto It will not work.

You need to edit the file /etc/security/pam_encfs.conf:

And file /etc/fuse.conf:

And add the user to the FUSE group:

$ sudo usermod - a - g fuse $ user

After entering the login, the Private directory can be used as a storage for personal data. It is worth it, however, it should be noted that the audit revealed some (serious enough) safety problems, which is why this system It is extremely recommended to use really important data to store.

Ecryptfs.
It is known that ECRYPTFS is used in Ubuntu as a default tool to protect home directories. Let's see how it works, we will create an encrypted directory manually. Install packages:

CreationCryptfs.

And I mount the FS (all necessary metadata are created when first mounted):

$ sudo Mount - T ECRYPTFS / HOME / ROM /. SECRET / HOME / ROM / SECRET

A password phrase will be requested (just once, the re-entering is not implemented, which looks not a very good solution, considering that it should be long), then the type of cipher (AES, Blowfish, 3DES, TWOFISH, CAST6 and CAST5) will be requested The key, the question is specified, allowing or disable the uninformed files in the directory with encrypted, encrypt if the names of the files ... and will ask the final, do you really wish to undermine and save signature to a specific file. The question is not so stupid as it may seem first: in this software, in the absence of signature, there is no possibility to distinguish the correct password from the wrong.

Encryption of the user's home directory

During the first launch, you may need to complete several processes. After encryption, you must immediately go to the user, and it will be proposed to write or print a password phrase generated for encryption and protected, in turn, user password. This is necessary for recovery in case of an emergency situation.


Warning to remember the password phrase

Let's see how to restore it. Suppose the password phrase is not recorded and recovery comes with Live CD. It is understood that the FS is implanted. Go to the home / .ecryptfs / rom / .ecryptfs directory and type:

dm-Verify.
The DM-Verify module is designed to check the integrity of block devices. Verification is carried out with Hash Tree, where "leaves" - hash-sums of blocks, and "branches" - hash-sums of the sets of "leaves". Thus, to verify the block device (whether it is a section or disk), it suffices to check only one checksum.
This mechanism (associated with a digital signature) is used in some Android devices to protect against modifying system sections, as well as in Google Chromium OS.

Conclusion
Linux contains really a lot of money for cryptographic information protection. Of the three funds described, at least one is present in all modern Linux distributions. But what to choose?
dm-Crypt / Luks It is worth applied in cases where it is possible to quickly disable the encrypted volume and when backups either not needed or classified by other ways. In this case, this solution is more than effectively, especially with the fact that it is possible to encrypt a cascade of arbitrary nesting and type (for example, AES-TWOFISH-AES) - a real paradise
For paranoids.
ecryptfs. Suitable in cases where the encrypted data must be saved somewhere - for example, in the cloud. It provides quite reliable combination (although in a 128-bit variant used by default, it is possible to reduce cryptopic resistance into two bits) and for the end user is transparent.
Encfs. The old man is about ten-year old, based on even more ancient work. To date, not recommended for use due to potential security holes, but can be used as a cross-platform to protect the nonsense data in the clouds.

If you need to use such funds, you should always remember that the protection must be complex.

: - English

The active development of the page is completed

If you have something to add, then complement the sections with new information. Our typos and errors in the article can be confused boldly, there is no need to report it to the mail, please comply with the style of this page and use sections separators (gray lines of different thicknesses).

Data encryption in Debian

Many it seems that you do not need to encrypt your data. However B. everyday life We often encounter such situations as "lost flash drive" or "Laptop is delivered to repair" ITP. If your data is encrypted, you can not worry about them at all: no one will publish them on the Internet, or does not take advantage of some other way.

Encryption using CryptSetup

Install the necessary components:

# APT-Get Install Cryptsetup

Standard syntax

/ dev / sda2. We introduce the command:

# CryptSetup Create SDA2_CRYPT / DEV / SDA2

This command will create an encrypted connection to our disk. In catalog / dev / mapper A new device will appear with the name we requested: / Dev / Mapper / SDA2_CRYPTWhen referring to which we use encrypted access to the disk. In the case of LUKS name will be / Dev / Mapper / SDA2_CRYPT

If the file has already had a file system and we would like to save data on it, then you must perform their encryption for subsequent use:

# DD if \u003d / dev / sda2 of \u003d / dev / mapper / sda2_crypt

If it is created new Disc On an empty section, you can format it:

# mkfs.ext3 / Dev / Mapper / SDA2_CRYPT

Subsequently, it will be possible to mount this disk anywhere:

# MOUNT / DEV / MAPPER / SDA2_CRYPT / PATH / TO / MOUNT / POINT

Check the data integrity (as usual, it is better to use only unmounted):

# FSCK.EXT3 / DEV / MAPPER / SDA2_CRYPT

And even decrypt back if we no longer want to use encryption:

# dd if \u003d / dev / mapper / sda2_crypt of \u003d / dev / sda2

LUKS Syntax

The above actions can be performed in accordance with LUKS Standard

Initialize the section:

CryptSetup LUKSFORMAT / DEV / SDA2

Connect to the system:

CryptSetup LUKSOPEN / DEV / SDA2 SDA2_CRYPT

Format:

MKFS.EXT4 -V -L DATA / DEV / MAPPER / SDA2_CRYPT

Mount:

MOUNT / DEV / MAPPER / SDA2_CRYPT / MNT / DATA

The section can be manually disable about the system.

CryptSetup Luksclose SDA2_CRYPT

Connection at startup

The file is used for this purpose. crypttab..

For our disk wept in it next line:

Nano / etc / Crypttab # name Mapper device key settings / options # with standard SDA2_CRYPT / DEV / SDA2 syntax None AES-CBC-Plain: SHA256 # and \\ or under LUKS SDA2_CRYPT / DEV / SDA2 NONE LUKS

By default, the password entered user encryption is used. Thus, every time you download your computer system will ask each time you have a password to connect each encrypted partition. Even if in FSTAB these sections are not spelled out.

If we want to mount manually, then add the option noauto. In the "Parameters / Options" field.

Connecting the encrypted section manually according to the data from / etc / crypttab

Cryptdisks_start msda2_crypt.

And shutdown with a pre-unmounted FS.

Cryptdisks_stop SDA2_CRYPT

To automatically mount the FS on the connected encrypted section, add a string to / etc / fstab

/ DEV / MAPPER / SDA2_CRYPT / MNT / DATA EXT4 Defaults 0 0

Work with keys in LUKS

The LUKS section supports 8 different keys, each of which is placed in its slot.

Let's see the list of keys used

CryptSetup Luksdump / Dev / SDA2

LUKS can use 2 types of keys - key phrases and files.

You can add key phrase

CryptSetup LuksaddKey / Dev / SDA2

You can add a key file (2048 BIT) and set access rights to it.

dd if \u003d / dev / urandom of \u003d / root / ext2.key bs \u003d 512 count \u003d 4 cryptsetup luksaddkey / dev / sda2 /root/ext2.key chmod 400 /root/sda2.key cryptsetup -d /root/sda2.key LUKSOPEN / DEV / SDA2 SDA2_CRYPT

To connect when starting the key / etc / crypttab

Nano / etc / crypttab sda2_crypt / dev / sda2 /root/sda2.key luks

You can delete the key phrase or key from the section.

CryptSetup Lukskillslot / dev / SDA2 1

Emergency Mounting in "Strank" distribution

Nobody is insured against problems and sometimes you need to access the encrypted partition from the emergency LiveCD disk.

Loading, connect the section into the system and mount the FS:

CryptSetup LUKSOPEN / DEV / SDA2 SDA2_CRYPT MOUNT -T EXT4 / DEV / MAPPER / SDA2_CRYPT / MNT / Backup

After work, unmount the FS and turn off the encrypted section from the system

Umount / MNT / Backup CryptSetup Luksclose SDA2_CRYPT

Error messages when switching off

If the root section is encrypted, then when you turn off the message will be issued

Stopping Early Crypto Disks ... Failed

This is a technical error. When you turn off, first of all, file systems are always dismantled and only then the partition is turned off. As a result, it turns out that the CryptSetup utility located on the root unmounted section is already inexplicable for launching, what we are init and reports. Without crutches, such a problem is not solved, because To do this, we need to consider options with the transfer of CryptSetup in the RAM disk

A similar situation folded and when using a software RAID containing the root section. eight)

Encryption using the LOOP-AES module

Encryption of the hard drive section, flash drives using a password

In this hOWTO The encryption method is described AES256.Other methods can be applied similarly (replacing the name of the method to the appropriate). We will need the following packages:

# APT-Get Install Loop-Aes-Utils Loop-Aes-Modules -`uname -r`

Note: If you use the kernel for which in the repository there is no needed Loop-Aes-Modules, you can set the modules by the following commands:

# APT-Get Install Module-Assistant Loop-Aes-Source # Module-Assistant A-I Loop-Aes

First stage

At the initial stage, we prepare the disk to work with it using encryption.

Select a section of the disk (or flash drives) which we want to encrypt, for example it will be / dev / sda2. We introduce the command:

# LOSETUP -E AES256 -T / DEV / LOOP0 / DEV / SDA2

After performing this command, all appeals to the device / Dev / Loop0 will be encrypted and in an encrypted form redirect to the device / dev / sda2. Now we have simultaneously encrypted and non-storage channels to the storage device. The data is encrypted using the password that you specified when executing Losetup.

Now we can for example format the device:

# MKFS.EXT3 / DEV / LOOP0

We can mount it:

# MOUNT / DEV / LOOP0 / PATH / TO / MOUNT

we can disable encryption:

# LOSETUP -D / DEV / LOOP0

and most importantly, we can encrypt the section without data loss:

# DD if \u003d / dev / sda2 of \u003d / dev / loop0

and also decipher if we decide that the encryption is not our method:

# DD if \u003d / dev / loop0 of \u003d / dev / sda2

Well, the most pleasant, we can check the file system for integrity:

# FSCK.EXT3 / DEV / LOOP0

This feature is not available in all methods of sections encryption.

Daily use

If you have already had a section on the section / dev / sda2 in your / etc / fstabYou need to just add options, and if it was not about the following:

/ DEV / SDA2 / Path / To / Mount Ext3 Loop, Encryption \u003d AES256 0 0

Now when loading the operating system, you will be requested by a password for mounting.

If you do not want the boot process interrupted by the password request, you can add options noauto.,user. In writing / etc / fstab:

/ DEV / SDA2 / Path / To / Mount Ext3 Loop, Encryption \u003d AES256, Noauto, User 0 0

Of course, you can mock manually (or from the script):

# MOUNT / DEV / SDA2 / PATH / TO / MOUNT -O LOOP, Encryption \u003d AES256

Mounting multiple file systems

Sometimes I want to encryptly encrypt several sections with the data, but so as not to enter the sea passwords for each mount. For example, you have a flash drive that you carry from home to work, portable Winchester, etc. Or just a few sections / hard drives.

Suppose we have an encrypted section / dev / sda2which we at each download mounted in the catalog / MNT1. A new winchester appeared / dev / sdb1 And we want it automatically mounted in the catalog mNT2. When mounting the first. You can of course create general System on something like LVM.However, you can and easily go:

we prescribe B. fSTAB Approximately the following line:

/ Dev / SDA2 / MNT1 Ext3 Noatime, Exec, Loop, Encryption \u003d AES256 0 0 / DEV / SDB1 / MNT2 Ext3 Noatime, Exec, Loop, Encryption \u003d AES256, CleartExtKey \u003d / MNT1 / KEY.TXT 0 0

The system when loading mounts points in the same order that is described in fSTABThus, if the first partition is not mounted, the key to mount the second partition will remain inaccessible and the second partition will not be mounted.

Password is stored as pLAIN / TEXT. It is certainly not very beautiful, but it is stored on an encrypted section (which can be unmounted). You can use instead gPG.-Well, however, this will not add a lot of security (if you can dig a key, then there will be a big difference what this key will not), the encryption option with gPG.-Chelch is described by B. man Losetup., here I will only give an example of writing in fSTAB:

/ Dev / SDA2 / MNT1 Ext3 Noatime, Exec, Loop, Encryption \u003d AES256 0 0 / DEV / SDB1 / MNT2 Ext3 Noatime, Exec, Loop, Encryption \u003d AES256, GPGKEY \u003d / MNT1 / KEY.GPG 0 0

Notes

For more information on supported encryption algorithms, see man Losetup., I can also see the description of other program options. losetup..

If you have problems installing the AES modules, then read the documentation running with the package lOOP-AES-SOURCE.

GRUB and encrypted root disk

When installing the root partition on the encrypted GRUB disk can show cracks in the main menu. This is due to the unavailability of the standard font /USR/Share/Grub/unicode.pf2. Copy font

cp /usr/share/grub/unicode.pf2 / boot / grub /

Indicate the setting

Nano / etc / Default / Grub grub_font \u003d / boot / grub / unicode.pf2

Apply the setting:

Update-Grub.