Encrypting A Linux Partition Using LUKS
Encrypting A Linux Partition Using LUKS
This encryption of the entire file system's is a much better way to secure the data on the disk. This is an added advantage for people who are prone to using mobile devices for their day to day work. The main advantage is that, even if the entire disk is lost, your data cannot be easily accessed as it is encrypted and requires a pass phrase key to access the data inside. Red hat implements this through LUKS.
What is LUKS?
LUKS stands for Linux Unified Key Setup. LUKS enables the facility to encrypt a whole partition in Linux for security purposes. LUKS was initially created by Clemens Fruhwirth. The main added advantage of using LUKS for encryption over other encryption technologies is that it is platform independent. In short you can call LUKS as a standard for implementing encryption of file system's in Linux.
Encryption upto the level of files cannot be done using LUKS It has got a limit regarding the no of users, that can have different passwords in order to access the same block device.
Are you sure? (Type uppercase yes): YES Enter LUKS passphrase: Verify passphrase: Command successful. You can replace "/dev/mapper/VolGroup00-myvolume" with whatever the partition you are going to encrypt with LUKS. The above cryptsetup command will ask for a confirmation, because this will destroy any data you have on the partition. Then you are prompted for a passphrase. Now lets see some detailed information about the encryption on our device /dev/mapper/VolGroup00-myvolume . [root@myvm ~]# cryptsetup luksDump /dev/mapper/VolGroup00myvolume LUKS header information for /dev/mapper/VolGroup00-myvolume Version: 1 Cipher name: aes Cipher mode: cbc-essiv:sha256 Hash spec: sha1 Payload offset: 1032 MK bits: 128 MK digest: 4f 4a 2e 9e 7e 04 44 e5 29 3e 6d d7 9e 56 17 2f 9f 5c bf 42 MK salt: a1 e5 ba 61 ce e9 48 7b 60 7e f2 e3 c5 61 53 22 f6 0b b2 8f ff 02 5f 56 62 0b 3d 3a 0f 7c c3 04 MK iterations: 10 UUID: a8ac8a06-baf8-4dbc-9c2b-52d3080e9fe3 Key Slot 0: ENABLED Iterations: Salt:
311917 d4 3e f3 37 5d 89 62 be d5 ab ee 27 de 17 b7 f8 cf 88 47 bf ab eb 2e 62 69 86 77 72 bc 26 a8 ed Key material offset: 8 AF stripes: 4000 Slot 1: DISABLED Slot 2: DISABLED Slot 3: DISABLED Slot 4: DISABLED Slot 5: DISABLED
Key Slot 6: DISABLED Key Slot 7: DISABLED You can clearly see from the above output that we are using aes encryption with sha256. Now lets see how are we going to access this newly encrypted device. Or in otherwords how will the kernel's device mapper recognize this encrypted partition of ours. You can get the UUID of the newly encrypted device as shown below. [root@myvm ~]# cryptsetup luksUUID /dev/mapper/VolGroup00-myvolume a8ac8a06-baf8-4dbc-9c2b-52d3080e9fe3 Now We will assign a device mapping name to this device as shown below. [root@myvm ~]# cryptsetup luksOpen /dev/mapper/VolGroup00-myvolume luks-a8ac8a06-baf8-4dbc-9c2b-52d3080e9fe3 Enter LUKS passphrase for /dev/mapper/VolGroup00-myvolume: key slot 0 unlocked. Command successful. Now You will have a device named "luks-a8ac8a06-baf8-4dbc-9c2b-52d3080e9fe3" in /dev/mapper. Also the above command luksOpen will depcrypt the filesystem so that it can be accessed [root@myvm mapper]# cd /dev/mapper/ ; ls control VolGroup00-LogVol01 luks-a8ac8a06-baf8-4dbc-9c2b-52d3080e9fe3 VolGroup00-myvolume VolGroup00-LogVol00 Please do remember that the device is open and accessible as of now because we ran "cryptsetup luksopen" command at the time of giving it a device mapping name. Now lets format our device in the same way we format our normal partitions. [root@myvm mapper]# mke2fs -j /dev/mapper/luks-a8ac8a06-baf8-4dbc9c2b-52d3080e9fe3 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 655360 inodes, 1310591 blocks 65529 blocks (5.00%) reserved for the super user First data block=0
Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. Now Lets mount this device, as normal. [root@myvm ~]# mount /dev/mapper/luks-a8ac8a06-baf8-4dbc-9c2b-52d3080e9fe3 /mypartition/ Now lets check and confirm whether our LUKS formatted and encrypted device is mounted properly with df -h command. [root@myvm ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 31G 2.7G 27G 10% / /dev/sda1 99M 13M 82M 13% /boot tmpfs 252M 0 252M 0% /dev/shm /dev/mapper/luks-a8ac8a06-baf8-4dbc-9c2b-52d3080e9fe3 5.0G 139M 4.6G 3% /mypartition We can clearly see from the last line of the above output that our newly mapped encrypted device is mounted under /mypartition
[root@myvm ~]# umount /dev/mapper/luks-a8ac8a06-baf8-4dbc-9c2b52d3080e9fe3 [root@myvm ~]# cryptsetup luksClose /dev/mapper/luks-a8ac8a06-baf84dbc-9c2b-52d3080e9fe3 The first command above unmounts and the second command locks back the filesystem.