Encrypt Your Ubuntu Home Folder - Step-by-Step Guide

Encrypting Your Ubuntu Home Folder After Installation
During the Ubuntu installation process, you are presented with the option to encrypt your home folder. Should you initially choose to forego encryption, it’s important to know that a complete reinstallation of Ubuntu isn't necessary if you later decide to enable this security feature.
Activation of encryption can be readily achieved through a series of commands executed in the terminal.
Understanding eCryptfs
Ubuntu leverages eCryptfs as its encryption system. This means that upon login, your home directory is automatically decrypted using your user password.
While employing encryption does introduce a degree of performance overhead, the benefit lies in safeguarding sensitive data, especially on portable devices like laptops that are potentially vulnerable to theft or loss.
Consider the following advantages of home folder encryption:
- Data Confidentiality: Protects your personal files from unauthorized access.
- Portability: Particularly crucial for laptops and other mobile devices.
- Flexibility: Encryption can be enabled even after the initial installation.
By utilizing eCryptfs, Ubuntu provides a robust and convenient method for securing your private information.
Initiating the Encryption Process
Prior to commencing the procedure, it is crucial to establish a backup of your home directory and all essential files. While the encryption command itself will generate a backup on your system, possessing an independent backup is highly recommended as a precautionary measure.
Begin by installing the necessary encryption tools:
sudo apt-get install ecryptfs-utils cryptsetup
The encryption of your home directory necessitates being performed while you are not currently logged in. Consequently, an alternative user account possessing administrator (sudo) privileges will be required. This account can be conveniently created through Ubuntu’s User Accounts interface.
Access this interface by clicking on your username in the panel and then selecting 'User Accounts'.
A new user account should now be created, ensuring it is granted administrative privileges.
A password must be assigned to the newly created account by clicking within the password field. The account will remain inactive until a password is set.
Following the creation of the user account, proceed to log out of your current desktop session.
Migrating Your Home Folder
Begin by selecting your newly created, temporary user account from the login screen and completing the login process using its credentials.
This will prepare the system for the subsequent encryption steps.

To initiate the encryption of your home directory, execute the following command in the terminal, ensuring you replace 'user' with your actual username:
sudo ecryptfs-migrate-home -u user
The system will prompt you for your user account’s password. Upon successful authentication, the home directory encryption process will commence, and crucial information will be displayed.
These notes can be summarized as follows:
- Immediate login with the alternate user account is required – prior to any system restarts.
- A backup of your original home directory has been created, providing a restoration point should access issues arise.
- Generating and securely storing a recovery phrase is strongly recommended.
- Encrypting the swap partition is also advised for enhanced security.

Proceed to log out of the temporary account and log back in using your original user account. It is vital to avoid rebooting the system before logging back in with your primary account!

Following login, a prompt will appear requesting you to create a recovery passphrase. Click the "Run this action now" button and ensure this passphrase is stored in a secure location, as it will be essential for manual file recovery if needed.

The ecryptfs-unwrap-passphrase command can be utilized at any time to reveal this recovery passphrase.
Securing the Swap Partition
During Ubuntu installation, if you choose to encrypt your home directory, the swap partition is automatically included in the encryption process. However, it's crucial to explicitly configure swap encryption following home directory encryption. This can be achieved by executing the subsequent command within a terminal window:
sudo ecryptfs-setup-swap
It’s important to understand that utilizing an encrypted swap space may introduce incompatibilities with the hibernation functionality in Ubuntu. Fortunately, hibernation is typically deactivated by default within the Ubuntu system.
Post-Encryption Cleanup
Following a system reboot and confirmation of proper functionality, a cleanup process can be initiated. This involves not only the removal of the temporary user account created during encryption, but also the deletion of the backup home directory.
The backup home folder resides within the system's /home directory and should be removed to free up disk space and maintain system organization.
Removing the Backup Directory
The backup directory must be removed via the command line interface. Utilize a command similar to the example provided below.
Extreme caution is advised when executing this command. Incorrectly specifying the directory path could lead to the accidental deletion of your actual home folder or other critical system files.
sudo rm -rf /home/user.random
Double-check the directory name before pressing Enter to ensure the correct backup folder is targeted for removal.
This command permanently deletes the specified directory and its contents, so verification is crucial.