Creating an Encrypted Partition….
This tutorial is meant to show how to either fully encrypt a USB Drive or partially encrypt it depending on how the partitions are set up. My intent with this is to create an encrypted partition of ~1 MB, with this I will be able to add in an ID file. To ensure integrity of that file a MD5 and SHA2 checksums will also be created but not stored on the disk.
One of the nice things about using cryptsetup (an implementation of LUKS – Linux Unified Key Setup) is that the standard is compatible on all Linux devices, meaning that if required the encrypted partition could be accessed using another computer. Another possible option is if you are encrypting for example an entire drive it is possible to create a keyfile which is required to unencrypt the drive which could be stored on your mobile device’s flash memory or a usb drive.
This was done using Ubuntu 10.04 (Lucid Lynx), the latest LTS version as of this writing. Remember whenever you are altering the file system on your disk the potential for things to go badly is high so backup your data!
Step 1: Install all the required Packages
First thing to do is to make sure all the packages needed are installed. In a terminal:
modprobe dm-crypt
Depending on your user permissions you may need to add ‘sudo’ to the beginning of these lines
Step 2: Set up the Disk Partition(s)
This can be with your favourite partition manager.
fdisk
gparted
Step 3: Zero out the disk
Given that the data being written is sensitive it’s a good idea to zero out the partition.
An easy way to accomplish this is by using dd.
For a higher security wipe it is advisable to write random data multiple times over the partition that is going to be encrypted to render the pre-existing data as unrecoverable as possible.
dd if=/dev/urandom of=dev/{partition id} bs=1M
Step 4: Check file system integrity
This is important to do before we start encrypting the partition to ensure that the drive’s file system integrity is not compromised.
Step 5: Encrypting the partition
The list of supported hashes is based off the gcrypt library. A list of the current supposed hashes can be found on the GNU PG Website within the gcrypt library manual.
-c = cipher specification string (the actual encryption algorithm used; default is sha256)
-s = key size in bits (must be multiple of 8; default is 256)
-h = choose hash format (currently default is sha1 which is known to be vulnerable to attack)
-y = verify passphrase (passphrase must be entered twice)
-v = verbose mode (I prefer to have it telling me what it’s doing as it goes along)
Step 6: Open the Encrypted Partition
Enter in the passphrase selected during the luksFormat Command, and if you entered it in correctly the encrypted partition will open allowing for files to be transferred into the newly encrypted partition.
I reformatted the encrypted partition to ext4 due to personal preference however any file system should work.
Step 7: Generating Checksums
MD5
Verify: md5sum -c {filename}.md5
SHA2
Verify: sha256sum -c {filename}.sha256sum
Step 8: Copying Files into Encrypted Partition
Credit goes to the tutorials from the Ubuntu Community Documentation which helped guide me during my initial attempts.
Recent Comments