Android devices store a lot of personal data – photos, documents, backups, and even app data. While the built‑in encryption protects the whole device, you may want to keep a specific set of files hidden from the system, cloud backups, or other users who might gain temporary access. An encrypted VeraCrypt container works like a virtual drive that is readable only after you provide the correct password. It offers strong, open‑source encryption (AES‑256, Twofish, etc.) and can be moved between devices.
This tutorial shows how to set up such a container using Termux, a lightweight terminal emulator for Android. No root is required; everything runs in user space.
Settings → Security → Install unknown apps for Termux (or allow from the Play Store) so it can execute binaries.pkg update && pkg upgrade -y
This ensures all repositories are current.pkg install git make clang wget tar proot -y
VeraCrypt’s source uses make and the clang compiler.termux-setup-storage
You will be prompted to allow storage access – tap Allow.VeraCrypt does not provide a pre‑compiled Termux package, so we compile it from source.
mkdir -p ~/src && cd ~/src1.26.7 with the current version if needed):
wget https://launchpad.net/veracrypt/trunk/1.26.7/+download/VeraCrypt_1.26.7_Source.tar.gztar -xzf VeraCrypt_1.26.7_Source.tar.gzcd VeraCrypt_1.26.7The source includes a Makefile with an Android target. The compilation may take 5‑15 minutes depending on your CPU.
ANDROID flag and start the build:
make clean && make -j$(nproc) GUI=none
The GUI=none option skips the graphical front‑end, which is unnecessary for command‑line use.
android-ndk or missing headers, install the NDK via Termux’s package manager:
pkg install ndk-sysroot -y
Then retry the make command.
veracrypt and veracrypt-mount appear in the src folder.cp src/veracrypt $PREFIX/bin/ && chmod +x $PREFIX/bin/veracryptmake install – it tries to install system‑wide files that require root.VeraCrypt containers are just regular files that act as virtual disks once mounted.
veracrypt --text --create ~/storage/shared/secure_container.hc --size 500M --encryption AES --hash SHA-512 --filesystem exFAT --pim 0 --keyfiles "" --random-source /dev/urandom
Explanation of the flags:
--text – forces command‑line mode.--create – creates a new volume.--size 500M – container size.--encryption AES – encryption algorithm (AES‑256 by default).--hash SHA-512 – hash algorithm for the header.--filesystem exFAT – file system usable on both Android and Windows/macOS.--pim 0 – Personal Iterations Multiplier; 0 means default.--random-source /dev/urandom – source of entropy.Mounting makes the encrypted volume appear as a directory you can read/write.
mkdir -p ~/veracrypt-mountveracrypt --text --mount ~/storage/shared/secure_container.hc ~/veracrypt-mount
You will be asked for the password you set earlier.VeraCrypt 1.26.7 successfully mounted.
Now any file you copy into ~/veracrypt-mount is stored encrypted on the underlying container file.ls -l ~/veracrypt-mount command to verify the mount point is accessible.You can treat the mount point like any other directory. Below are common tasks.
cp /sdcard/Download/secret.pdf ~/veracrypt-mount/~/veracrypt-mount via the Termux storage shortcut. Alternatively, use termux-open:
termux-open ~/veracrypt-mount/secret.pdfls -lh ~/veracrypt-mountImproper unmounting can corrupt the filesystem inside the container.
veracrypt -d ~/veracrypt-mount
The -d flag tells VeraCrypt to dismount the specified mount point.ls ~/veracrypt-mount
It should return “No such file or directory” or an empty list.The container file is a single, portable entity. Back it up like any other file.
rsync over Wi‑Fi to another Android device or a PC.If VeraCrypt compilation fails on your device (e.g., due to missing glibc support), you can fall back to Linux Unified Key Setup (LUKS) via the cryptsetup package available in Termux.
pkg install cryptsetup -ydd if=/dev/zero of=~/storage/shared/luks_container.img bs=1M count=200cryptsetup luksFormat ~/storage/shared/luks_container.imgcryptsetup open ~/storage/shared/luks_container.img myvaultmkfs.ext4 /dev/mapper/myvaultmkdir -p ~/luks-mount && mount /dev/mapper/myvault ~/luks-mountumount ~/luks-mount && cryptsetup close myvaultLUKS offers comparable security, but VeraCrypt is more portable across Windows, macOS, and Linux because the container file can be opened with the free VeraCrypt GUI on those platforms.
| Problem | Possible Cause | Fix |
|---|---|---|
Compilation fails with error: unknown type name ‘__builtin_expect’ | Missing recent clang headers. | Run pkg install clang again, then make clean && make. If still fails, install the ndk-sysroot package. |
| Mount command returns “Invalid password or volume is not a VeraCrypt volume”. | Wrong password or corrupted container. | Double‑check the password. If you suspect corruption, recreate the container and restore files from backup. |
After mounting, ls shows “Permission denied”. | Termux storage permission not granted. | Run termux-setup-storage again and accept the Android permission dialog. |
| Container size is smaller than expected. | Incorrect --size syntax (e.g., using MB vs. MiB). | Use --size 500M for megabytes; --size 500MiB for mebibytes. Re‑create with the correct flag. |
| Unmount fails with “device is busy”. | Some app still has an open file handle. | Close all file managers, stop background copies, and run lsof | grep veracrypt-mount to find the culprit, then kill the process. |
By following this tutorial you now have a portable, AES‑256 encrypted container that lives on your Android device, accessible only after you provide the correct password. The container can be backed up, transferred, and opened on Windows, macOS, or Linux with the standard VeraCrypt GUI, giving you a seamless cross‑platform security solution without ever rooting your phone.
Feel free to experiment with larger containers, different file systems (NTFS for Windows compatibility), or multiple containers for separate data categories. As always, treat your passwords and backups with the same care you would any other valuable asset.









