Contents
Description
Below is a list of instructions on how to encrypt your hard disk space, both the main storage partition and the swap space, however it's quite unfortunate that there hasn't been better development in trying to protect the boot space as well, and at this point in time it's a cause for concern if you walk away from a PC and someone installs a password capture script in the mix.
First things first
I cannot stress strongly enough how you should backup your data, even if you haven't lost a single bit of information in the past there will come a time when you will, so please please please backup anything you think you may loose because the following steps will involved a repartitioning and/or formatting.
Ubuntu/Debian Specific Information
Background
Since I'm a Debian/Ubuntu fan I've only had experience with those distros, tools for other distros especially in relation with kernel modules tend to vary greatly so you may need to do some extra digging.
Getting and building the kernel module
You will need to install a few packages and have the system build and install a replacement loop kernel modules.
cd /usr/src apt-get install loop-aes-utils linux-headers-`uname -r` linux-source gnupg sharutils module-assistant fakesource module-assistant auto-install loop-aes rmmod loop modprobe loop
You will now need to generate a GPG key to use to use against your encrypted partitions. This is the biggest downside to loop-aes is the fact it forces you to use GPG, if it used pam for it's authentication then it would be a snap to use a x.509 pki token to have a much more secure system.
head -c 2880 /dev/urandom | uuencode -m - | head -n 65 | tail -n 64 | gpg --symmetric -a > /root/keyfile.gpg
Preparing the Harddisk
If you are thinking of utilising an entire hard drive (or even just a partition) that you previously had sensitive information stored unencrypted, you should think about wiping the hardrive in a proper manner that doesn't occur through normal wiping or formating.
If you are able to spare an entire computer for up to a week I'd suggest using something like dban, this is a self contained bootable linux image, and all it does is overwrite your hard drive up to 35 times with random information to ensure privacy. Alternatively you can just use dd.
for i in `seq 1 35` do dd if=/dev/urandom of=/dev/hda bs=4k done
Methods of encrypting data
Encrypting a loop back file
There are a number of way to encrypt your data, firstly you can use loop back with a file on an existing hdd, but this is rather slow in comparision to encryting the entire partition, but in some cases you may only want to protect a limited number of files, and don't care about the rest of the information.
You will need to make a new file, in this case we will be using /home/loop as the example. I'm going to be using 1 megabyte block sizes, and 256 of them (so 1 256M file system).
dd if=/dev/zero of=/home/loop bs=1M count=256 head -c 15 /dev/urandom | uuencode -m - | head -n 2 | tail -n 1 | losetup -p 0 -e AES256 /dev/loop0 /home/loop losetup -d /dev/loop0 mkdir /home/crypto
Next to have the partition more easily mountable you'll want to add the following to the /etc/fstab file.
/home/loop /home/crypto reiserfs defaults,noauto,loop=/dev/loop0,encryption=AES256,gpgkey=/root/keyfile.gpg 0 0
Finally you can mount and format the partition
losetup -F /dev/loop0 mkreiserfs /dev/loop0 losetup -d /dev/loop0 mount /home/crypto
Once this all finishes, if you run df -h you should see something like:
/home/loop 256M 33M 224M 13% /home/crypto
Encrypting a disk partition
This is the most efficient method, since you won't suffer the problem of having a file system sitting on top of a potentially fragmented file system.
I currently have 3 partitions on my harddrive, /dev/hda1 is my boot/root partition, /dev/hda2 is my swap partition (scroll down for details on encrypting your swap space and why) and /dev/hda3 which is my /home partition, things I want encrypted from the root/boot partition are copied onto this partition and symlinked.
head -c 15 /dev/urandom | uuencode -m - | head -n 2 | tail -n 1 | losetup -p 0 -e AES256 /dev/loop0 /dev/hda3 losetup -d /dev/loop0 mv /home /home-old
Next to have the partition more easily mountable you'll want to add the following to the /etc/fstab file. Please note that I stored my keyfile.gpg in /etc as I want /root in my encrypted file space.
/dev/hda3 /home/crypto reiserfs defaults,noauto,loop=/dev/loop0,encryption=AES256,gpgkey=/etc/keyfile.gpg 0 0
Finally you can mount and format the partition
losetup -F /dev/loop0 mkreiserfs /dev/loop0 losetup -d /dev/loop0 mount /home
Once this all finishes, if you run df -h you should see something like:
/dev/hda3 256M 33M 224M 13% /home
Encrypting your swap space
It's extremely important to encrypt swap space because if something sensitive is swapped out from ram to hard drive space you might end up needing to run DBAN over the hard drive for the best part of a week to make sure no one else can get it.
loop-aes makes it very simple to encrypt swap space, and to boot it generates and uses a new random key each time. To enable this, simply modify your fstab entry for swap space:
before:
/dev/hda2 none swap sw 0 0
after:
/dev/hda2 none swap sw,loop=/dev/loop7,encryption=AES256 0 0
Using OpenSSL instead of GPG
Not all the details have been worked out, mostly with respect to using USB tokens for authentication rather then a password.
To generate the HDD key file do the following instead:
head -c 2880 /dev/urandom | uuencode -m - | head -n 65 | tail -n 64 | openssl aes-256-ecb > /etc/keys/user.key
To use this key to mount/initialise a partition:
dd if=/dev/zero of=/loop bs=1M count=256 openssl aes-256-ecb -d -in /etc/keys/user.key|losetup -p 0 -e AES256 /dev/loop0 /loop mkreiserfs /dev/loop0 mount /dev/loop0 /mnt
Notes
There are other methods for encryption under linux however most seem to have flaws in the implementation or aren't as efficent and so bog your system down as a result, or worst yet leave you vulnerable with a false sense of security, or both!
- After doing testing on the same loop file with AES128, 192 and 256 I saw very little difference in terms of time or CPU consumed of a 1G file and I'd suggest using AES256 as it gains you a lot in terms of time to break etc.