Encrypted swapfile

Sometimes, it’s worth to encrypt swap space, especially if you process some privacy-sensitive data.
# install cryptsetup
sudo apt-get install cryptsetup

# generate swap
sudo truncate -s 1GB /cryptswap
sudo mkswap /cryptswap

# add to /etc/crypttab
cryptswap /cryptswap /dev/urandom swap

# add to /etc/fstab
/dev/mapper/cryptswap none swap sw 0 0

# activate encryption and swap
sudo /etc/init.d/cryptdisks reload && sudo swapon -a

Inspired by AskUbuntu.