Encrypted swapfile

Sometimes, it’s worth to encrypt swap space, especially if you process some privacy-sensitive data.
[bash]
# 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
[/bash]

Inspired by AskUbuntu.

Advertisements

Setup swap in EC2 instance

[bash]
# configure 2GB swap (1M x 1024 blocks)
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
sudo mkswap /swapfile
sudo swapon /swapfile

# add swap info to /etc/fstab
/swapfile swap swap defaults 0 0
[/bash]