updated Nov 29, 2019

Linux partition encryption with cryptsetup

Partition encryption is good option to protect your data in case your computer has been stolen or lost.

Install cryptsetup

Run command in Ubuntu command line:
sudo apt-get install cryptsetup

Partition setup

Choose empty partition for encryption, run the command in shell to format:
sudo cryptsetup luksFormat /dev/sdb1
The command will ask passphrase that will be used on mapping partition each time so you should remember it.

Map partition and create file system:

    sudo cryptsetup open /dev/sdb1 crypted
    sudo mkfs.ext4 /dev/mapper/crypted

Mount partition

One time action: in mnt folder create crypted folder where the crypted partition will be mounted.
Execute commands to mount and enter passphrase you entered on the partition setup:
sudo cryptsetup --type luks open /dev/sdb1 crypted
sudo mount -t ext4 /dev/mapper/crypted /mnt/crypted
The partition is available at /mnt/crypted folder.