SLACKWARE ENCRYPTED SWAP
Enabling Encrypted Swap on Slackware - A How-To
When available memory drops below a certain point, the Linux kernel will swap the contents of memory pages to swap space.
This content may include sensitive information such as passwords, usernames, PINS, banking or other identity information. This data is usually in plain text and so can be read without effort. Encrypting the system swap space protects its contents against unauthorized access and attack should access to the hard drive be compromised or physically removed.
Setting up Encrypted Swap
The following discussion will use several drive and partition designations. Be sure when implementing the procedures to adjust these to suit your own system.
The steps that follow can be used when initially setting up a system, or after a system is already running. If the latter, the first step required to encrypt the swap partition is to temporarily turn off swap. Close all unnecessary applications to free used memory and thereby discontinue the use of the swap space. While many applications can be configured to not use swap, this does not apply to the kernel. If the swap space is still being used, you will be unable to turn off swap.
Though not necessary, perhaps the simplest approach is to boot the system into single user mode. This results in minimal services running and a single root shell.
Swap can then be turned off using the following command:
# swapoff -a
To ensure a completely clean and sterile swap space, you must overwrite the previously used swap partition with random data. This will help prevent the recovery of any data written to swap before the encryption process. There are several ways to do this.
Perhaps the easiest is using the shred command which overwrites the specified file or device with random data
# shred -v /dev/sdaX
Alternatively, overwriting the space with randow data from either /dev/random or /dev/urandom
# dd if=/dev/random of=/dev/sdaX bs=512
# dd if=/dev/urandom of=/dev/sdaX bs=512
Note: that /dev/urandom is not quite as secure however it is significantly faster than using /dev/random.
The next step is to create a file, if it doesn't already exist, named crypttab in /etc. The specifics for crypttab can be found in the man page.
A crypttab entry as follows creates an encrypted block device named swap at /dev/mapper using the partition /dev/sdX as the base block device and /dev/random as the encryption password using AES encryption and variable initialization vectors.
swap /dev/sdaX /dev/random swap,cipher=aes-xts-essiv:sha256
You then need to edit /etc/fstab to point to the encrypted block device, /dev/mapper/swap as opposed to /dev/sdaX.
For example a current entry of:
/dev/sdaX swap swap defaults 0 0
/dev/mapper/swap swap swap defaults 0 0
Activating Encrypted Swap
You can now enable encrypted swap either by rebooting the system or by issuing the following commands at the console prompt.
# cryptsetup -d /dev/random create swap /dev/sdaX
# mkswap /dev/mapper/swap
# swapon -a
For detailed information on specific commands please see the individual manual (man) pages.
This document has been submitted to the Slackware Documentation Project.
WE’VE GOT OUR EYES ON YOU !
A PRAYER OF REMEMBRANCE
Previous content can be found in the Archives.
Céad Míle Fàilte. A h-uile là sona dhuibh ’s gun là idir dona dhuib.
(100,000 Welcomes. May all your days be happy ones.)
Another day of pushing electrons . . . welcome to my corner of the internet. It's a busy place out there and this is a small pool of quietude amongst the flash and bustle of the web; what I like to refer to as my "castle in cyberspace". The site is designed to maximize ease of content use. After all, content is what you browse the web for . . . isn't it?
Milner Manor, a.k.a. The Birches, located on Cape Breton Island, is the personal web site of W. Dean Milner and contains an eclectic collection of articles and musings of various sorts as well as references to other interesting sites.
January 17, 2012
The wheels of government grind slowly, including those maintaining registries and websites but my Grandfather's record catch for speckled trout is finally on the Nova Scotia Sport Fishing Registry web site.
June 21, 2011
The swapshop (fleamarket) section is being slowly updated after being neglected for a while in favour of the Virtual Fleamarket pages.
- SLACKWARE ENCRYPTED SWAP
- CLOUD RELIABILITY
- WE’VE GOT OUR EYES ON YOU !
- A PRAYER OF REMEMBRANCE
- THE LITTLE DUTCH GIRL’S COAT
- BOOK REVIEW: RECURSION
- WINTER AUTOMOBILE STORAGE
- EXPAND YOUR HOSTING STORAGE
- CONSIDERING HIRING A CONTRACTOR ?
- THE FIRST CLICK
(From the other side of nowhere)
A useful article on creating a bootable USB flash drive is available at TechRepublic.