Lecture 55 LUKS Encryption in Linux
Lecture 55 LUKS Encryption in Linux
LUKS.
---------------------
In this guide, we are about to see how to create an encrypted file system in Red
Hat Enterprise Linux, CentOS or any other RHEL based Linux variants.
We will use the Linux Unified Key Setup (LUKS) to encrypt the filesystem to prepare
our encrypted filesystem.
Once all the setups are done, make sure to backup your key and passphrase. FYI, if
we forgot the key or passphrase for LUKS1 devices
it’s possible to recover the key/Passphrase, however, it’s not possible to recover
if you are using a LUKS2 device. Because the key stored directly in the kernel.
Installing Cryptsetup
In a minimal installed RHEL or CentOS by default it won’t get installed, to start
with the encryption setup first we need to install the required packages.
# fdisk -l /dev/sdb
[root@rhel7 ~]#
Mounting the Filesystem
Create a mount point to mount the created file system.
# mkdir /myfiles
# mount /dev/mapper/myfiles /myfiles
# df -h /myfiles
[root@rhel7 ~]# mkdir /myfiles
[root@rhel7 ~]#
[root@rhel7 ~]# mount /dev/mapper/myfiles /myfiles
[root@rhel7 ~]#
[root@rhel7 ~]# df -h /myfiles
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/myfiles 20G 45M 19G 1% /myfiles
[root@rhel7 ~]#
Persistent mount
The above steps are non-persistent during reboot. To make the encrypted filesystem
persistent during reboot we need to follow with below three steps.
Create a file with random data to make it as key for the encrypted mount point.
Make sure to change the ownership and permission for the created key as 600.
Moreover never put this file inside the encrypted filesystem which you have
created.
# vi /etc/crypttab
myfiles /dev/sdb /etc/crypt_file
# vi /etc/fstab
/dev/mapper/myfiles /myfiles ext4 defaults 0 0
Let’s take a reboot to confirm the functionality.
# reboot
Before reboot, cross check the fstab and crypttab for any misconfigurations.
#umount /myfiles
# mount -a
# cd /myfiles
# cat cal.txt
# exit
# umount /myfiles
# mount /myfiles
-----------------------
Delete the Existing LUKS Key on the device.
# cryptsetup luksRemoveKey /dev/sdb
-----------------------
Remove or Delete the LUKS:
# cryptsetup remove /dev/sdb
================
Thanks for watching the video. Please like our videos, share with your friends and
feel free to ask anything, post your queries in comments section. We will be glad
to answer your queries. Don't forget to subscribe the channel & turn on the bell
notifications.
===============