Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Encrypt Files and Folder VeraCrypt Ubuntu

· 7 min read · Home Tech

In this article
  1. What VeraCrypt Does and How It Works
  2. Installing VeraCrypt on Ubuntu
  3. Creating an Encrypted Container for Files and Folders
  4. Encrypting an Existing Folder In-Place
  5. Common Problems and How to Fix Them
  6. Safety and Backup Considerations
  7. Alternatives to VeraCrypt on Ubuntu
  8. Frequently Asked Questions

Yes, you can encrypt files and folders on Ubuntu using VeraCrypt, a free, open-source disk encryption tool. It creates encrypted containers (virtual disks) that you mount and unmount as needed, or it can encrypt entire partitions and system drives. This guide covers the practical steps for encrypting files and folders on Ubuntu with VeraCrypt, along with important background, safety considerations, and common troubleshooting.

What VeraCrypt Does and How It Works

VeraCrypt is a successor to the discontinued TrueCrypt project. It encrypts data in real time (on-the-fly) using strong ciphers like AES, Serpent, and Twofish, often combined in cascades (e.g., AES-Twofish-Serpent). When you mount a VeraCrypt volume, it appears as a separate drive in your file manager; you can copy, edit, and delete files inside it, and they are automatically encrypted before being written to disk. When you unmount the volume, the data becomes inaccessible without the correct password or keyfile.

For files and folders, the most common approach is to create an encrypted container—a single file that acts as a virtual disk. This container can be stored anywhere (on your hard drive, USB stick, or cloud storage) and is just a blob of random-looking data when not mounted. You can also encrypt a whole partition or the entire system drive, but that is a more advanced operation.

Installing VeraCrypt on Ubuntu

VeraCrypt is not in the default Ubuntu repositories, so you need to download it from the official website or use a third-party repository. The official distribution provides .deb packages for Debian/Ubuntu, as well as a .tar.gz archive for manual installation. As of the latest stable release (version 1.26.x), the .deb package installs cleanly on Ubuntu 22.04 and 24.04.

  1. Go to veracrypt.fr and download the appropriate .deb package for your architecture (usually amd64).
  2. Open a terminal in the directory containing the downloaded file and run sudo apt install ./veracrypt-1.26-*.deb (replace the filename with the actual one).
  3. If you get a dependency error, run sudo apt --fix-broken install and then retry.
  4. Launch VeraCrypt from the applications menu or by typing veracrypt in the terminal.

Alternatively, you can use the PPA maintained by the community, but the official package is the safest choice. Always verify the integrity of the downloaded file using the SHA-256 checksum provided on the download page.

Creating an Encrypted Container for Files and Folders

This is the most straightforward way to encrypt a group of files or folders. You create a container, mount it, and then move your sensitive data into it. The container size is fixed at creation, so plan ahead.

  1. Open VeraCrypt and click Create Volume.
  2. Choose Create an encrypted file container and click Next.
  3. Select Standard VeraCrypt volume (or Hidden volume for plausible deniability, but that is an advanced topic).
  4. Click Select File and choose where to save the container. Give it any name, e.g., MyVault.hc. Note: the file does not exist yet; VeraCrypt will create it.
  5. Set the encryption algorithm (AES is fast and secure) and hash algorithm (SHA-512 is fine).
  6. Set the size of the container in MB or GB. For example, 100 MB for a few documents, 5 GB for photos and videos.
  7. Choose a password. Use a long passphrase (at least 20 characters) with a mix of letters, numbers, and symbols. Do not forget it—there is no recovery.
  8. Select a filesystem. For Ubuntu, ext4 is recommended, but if you need to access the container from Windows too, choose NTFS or FAT (FAT has a 4 GB file size limit).
  9. Move your mouse randomly in the window for a few seconds to generate randomness, then click Format. This creates the container.

Once created, you can mount it: select a drive letter (e.g., 1) in the main VeraCrypt window, click Select File, choose your container, enter the password, and click Mount. The container will appear as a mounted volume in your file manager. Copy files into it, and when done, unmount it by right-clicking the volume and selecting Dismount.

Encrypting an Existing Folder In-Place

VeraCrypt does not have a “right-click to encrypt” feature like some other tools. To encrypt an existing folder, you must first create a container and then copy the folder’s contents into it. After verifying the copy, you can securely delete the original folder (using shred or wipe for better security, though the standard rm leaves traces on solid-state drives).

If you want to encrypt a folder without moving files, you could encrypt the entire partition that contains the folder, but that is overkill for most users. Another option is to use encfs or gocryptfs, which encrypt individual directories, but those are separate tools with different security models. For most purposes, a VeraCrypt container is the simplest and most robust solution.

Common Problems and How to Fix Them

Here are a few issues you might encounter:

  • “Failed to set up a loop device” – This usually means your user lacks permission. Run VeraCrypt with sudo or add your user to the disk group (sudo usermod -aG disk $USER), then log out and back in.
  • Container won’t mount after copying to a new system – Ensure the container file is not corrupted. Check the SHA-256 checksum if you have it. Also, make sure you are using the correct password and that the container is not already mounted.
  • Slow performance – VeraCrypt uses CPU encryption; on modern CPUs with AES-NI, it is fast. If you are using a cascade like AES-Twofish-Serpent, it will be slower. Choose AES alone for best speed.
  • Cannot see mounted volume in file manager – Sometimes the volume mounts but doesn’t auto-open. Check the VeraCrypt main window; you can also access it via the path like /media/veracrypt1.

Safety and Backup Considerations

The biggest risk with encryption is losing access to your data. There is no backdoor; if you forget the password, your data is gone forever. Therefore:

  • Always use a strong, memorable passphrase. Consider writing it down and storing it in a safe place (not on your computer).
  • Back up your container file regularly. If the file gets corrupted, you lose everything. Keep a backup on an external drive or cloud storage (the container is encrypted, so it’s safe to store online).
  • When you mount a container, it is decrypted in memory. If your system crashes or you unmount improperly, the container may become corrupted. VeraCrypt has a repair tool, but it’s not guaranteed to work. Always dismount cleanly.
  • Be aware of hidden volumes if you face coercion or legal pressure—they allow you to reveal one password while hiding another set of data. This is an advanced feature but worth knowing about.

Alternatives to VeraCrypt on Ubuntu

VeraCrypt is not the only option. Here are a few alternatives, each with trade-offs:

  • LUKS (Linux Unified Key Setup) – The native Linux disk encryption standard. It is integrated into the kernel and is excellent for encrypting entire partitions or system drives. You can use it for files via cryptsetup and loop devices, but it’s less user-friendly for individual files.
  • gocryptfs – A file-based encryption overlay. It encrypts individual files and directories, and is great for cloud sync (e.g., only changed files are re-encrypted). It is simpler than VeraCrypt for folders.
  • Cryptomator – A cross-platform tool that encrypts a folder structure, designed for cloud storage. It has a GUI and works on Ubuntu, but it is not a disk encryption tool; it is per-file encryption.
  • EncFS – An older tool that encrypts individual files. It has known security weaknesses (e.g., metadata leaks) and is not recommended for new projects.

For most users who want to encrypt a set of files or folders on Ubuntu, VeraCrypt offers the best balance of security, cross-platform compatibility, and ease of use.

Frequently Asked Questions

Can I encrypt a single folder without creating a container?

VeraCrypt does not support encrypting a folder in-place. You must create a container and move the folder into it. If you want to keep the folder in its original location, consider using gocryptfs or Cryptomator, which encrypt directories directly.

Is VeraCrypt safe to use on Ubuntu?

Yes, VeraCrypt is widely used and audited. It is open-source, and its source code has been independently reviewed. However, no software is perfect; keep your system updated and use a strong password. Also, be aware that VeraCrypt is not a replacement for full-disk encryption if you want to protect against physical theft of your device.

How do I mount a VeraCrypt container automatically at startup?

You can add a mount command to your startup applications. For example, create a script that runs veracrypt --mount /path/to/container /media/veracrypt1 --password=yourpass (but storing the password in a script is insecure). Better to use a keyfile or mount manually. There is no official auto-mount feature in the GUI.

Can I use VeraCrypt on Ubuntu to encrypt a USB drive?

Yes. You can create a VeraCrypt container on the USB drive, or encrypt the entire USB partition. The latter is more complex and will make the drive unreadable on systems without VeraCrypt. A container is more portable—you can copy it to any drive and open it on any system with VeraCrypt installed.

What happens if I forget my VeraCrypt password?

There is no recovery. VeraCrypt does not have a backdoor or password reset. If you forget the password, you lose access to the data permanently. Always keep a backup of the container and a written copy of the password in a secure location.