Ubuntu 14.04 Encrypted Swapfile Setup

From myWiki

In the installed system, first make a swap container. N is the size you want in megabytes and if you've got 4GB or more of memory and you're not working on a server, then a minimum swap size of half your system's RAM is realistically sufficient. Below 4GB, a swap size of 75 to 100 percent of the RAM available is good.

sudo dd if=/dev/urandom of=/swapfile bs=1M count=N

Then make the actual swap filesystem and restrict its permissions so that only the root user can read and write to it.

sudo mkswap /swapfile
sudo chmod 0600 /swapfile

Add it to fstab.

/swapfile  none  swap  sw  0 0

And last, switch it on. No reboot necessary.

sudo swapon /swapfile