Encrypt your data using LUKS (Linux)
August 21, 2015
Hello guys, In this article I will tell you how to encrypt your partitions in RHEL 6.0. Luks(“Linux unified key setup”) is the standard format for device encryption.This kind of encryption makes your partitions password protected before the file system in it can be mounted.
First we create a partition using fdisk. If you do not know how to create a partition using fdisk,you can explore the man file for fdisk where you will find the procedure to create partitions.After you have created the partition,run the following commands in order.
[email protected]# cryptsetup luksFormat /dev/sdaX
here X is the partition number.
This will ask you to enter a password. After this run
bash script for find all files which size is higher than given size in parameter and archive [email protected]# cryptsetup luksOpen /dev/sdaX name
here name is name of the device and can be anything,for eg:
cryptsetup luksOpen /dev/sda5 secret
This will ask for a password,enter the same password you created with luksFormat.
Now format the partition as
[email protected]# mkfs.ext4 /dev/mapper/secret
create a directory to mount the file system
[email protected]# mkdir /test
[email protected]# mount /dev/mapper/secret /test
For permanent mounting,edit /etc/fstab as follows
/dev/mapper/secret /test ext4 defaults 1 2
If you want that password should be asked everytime the machine boots then create a file /etc/crypttab and make following entries
This will ask for password every time your machine boots.
When finished working you can again lock the partition by
[email protected]# umount /dev/mapper/secret
>[email protected]# cryptsetup luksClose secret
Thus we see there are three stages while encrypting a partition
1) Encrypting a partition with a password.
2) Decrypting a partition and mounting the file system.
3) Again encrypting the partition