Backing up photos is easy, but keeping them private is another story. By creating an encrypted archive you protect your memories from accidental exposure, theft, or loss of the backup media. This tutorial shows how to use the free Termux terminal app together with OpenSSL to produce a single, password‑protected archive of every picture stored on your device – all without rooting.
2 × the size of your photo library available.$.termux-setup-storage~/storage directory with symlinks to ~/storage/shared (your shared internal storage) and ~/storage/downloads.
Termux ships with its own package manager (pkg) that pulls binaries compiled for Android’s ARM/ARM64 architecture.
pkg update && pkg upgrade -yopenssl (for encryption) and tar (for archiving):
pkg install -y openssl tarrsync if you want to copy only new photos in future backups.
pkg install -y rsyncMost Android devices store pictures under DCIM/Camera and Pictures folders on the shared storage. Termux accesses them via the ~/storage/shared symlink.
cd ~/storage/sharedls -d DCIM Camera PicturesWe’ll copy all images to a single folder before archiving. This avoids pulling the entire shared tree, keeping the archive size predictable.
mkdir -p ~/photo_backup/tmpNow copy the images. The command below copies common image formats (jpg, jpeg, png, heic, webp) while preserving the original folder structure.
find DCIM Pictures -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.heic" -o -iname "*.webp" \) -exec cp --parents {} ~/photo_backup/tmp/ \;If you have a separate folder for screenshots (Pictures/Screenshots), add it to the find command or run a second find with the same pattern.
Now that all photos are gathered in ~/photo_backup/tmp, we compress them into a single .tar file. Compression is optional – the encryption step already adds some overhead.
cd ~/photo_backup
tar -cvf photos.tar -C tmp .After the command finishes you’ll see a photos.tar file in ~/photo_backup. Verify its size matches the total size of your copied images.
OpenSSL’s aes-256-cbc cipher provides strong symmetric encryption. We’ll ask for a password interactively so it never appears in a shell history.
openssl enc -aes-256-cbc -salt -in photos.tar -out photos.tar.encWhen prompted, type a strong password (minimum 12 characters, mix of letters, numbers, symbols). Confirm it. OpenSSL will write photos.tar.enc – the encrypted archive.
Warning: Do not lose the password. OpenSSL does not embed a recovery key, and the original photos.tar will be deleted in the next step.
Even though the photos.tar file resides only in Termux’s private storage, it’s still readable by any app with file‑system access. To reduce risk we overwrite it before deletion.
# Overwrite with random data (size equal to the original file)
dd if=/dev/urandom of=photos.tar bs=1M count=$(stat -c %s photos.tar) conv=notrunc
# Remove the file
rm -f photos.tarIf dd reports “No space left on device”, it means the temporary space is insufficient – increase free storage or split the backup into multiple archives.
At this point you have photos.tar.enc in ~/photo_backup. Copy it to external storage, a computer, or a cloud service you trust. Because the file is encrypted, storing it on an insecure medium does not expose the images.
cp photos.tar.enc ~/storage/shared/Backup/adb pull /data/data/com.termux/files/home/photo_backup/photos.tar.enc /path/on/pc/After confirming the copy succeeded, you may delete the Termux folder to reclaim space:
rm -rf ~/photo_backupBefore you consider the job done, test that the encrypted file can be decrypted and that the resulting archive contains the expected photos.
openssl enc -d -aes-256-cbc -in photos.tar.enc -out test_photos.tartar -tvf test_photos.tar | headrm -f test_photos.tarIf decryption fails, double‑check the password and ensure the file wasn’t corrupted during transfer.
Repeating the whole process manually is tedious. You can create a small shell script in Termux that runs the steps you need. Below is a minimal example that you can save as backup_photos.sh and execute with bash backup_photos.sh:
#!/data/data/com.termux/files/usr/bin/bash
set -e
# 1. Prepare temporary folder
TMPDIR=~/photo_backup/tmp
mkdir -p "$TMPDIR"
# 2. Copy new photos (rsync only copies changed files)
rsync -av --include='*/' --include='*.jpg' --include='*.jpeg' --include='*.png' --include='*.heic' --include='*.webp' --exclude='*' ~/storage/shared/DCIM/ "$TMPDIR/"
rsync -av --include='*/' --include='*.jpg' --include='*.jpeg' --include='*.png' --include='*.heic' --include='*.webp' --exclude='*' ~/storage/shared/Pictures/ "$TMPDIR/"
# 3. Create tar
cd ~/photo_backup
tar -cvf photos.tar -C tmp .
# 4. Encrypt (prompt for password)
openssl enc -aes-256-cbc -salt -in photos.tar -out photos.tar.enc
# 5. Securely delete plain tar
dd if=/dev/urandom of=photos.tar bs=1M count=$(stat -c %s photos.tar) conv=notrunc
rm -f photos.tar
# 6. Cleanup
rm -rf "$TMPDIR"
echo "Backup complete: $(date)"Make the script executable with chmod +x backup_photos.sh. Run it whenever you want a fresh encrypted snapshot.
openssl package may have failed to install. Retry pkg install openssl and watch for error messages.ln -s /storage/XXXX-XXXX/photo_backup ~/photo_backup.termux-setup-storage and granted the permission dialog. If the dialog was dismissed, run the command again.The .tar.enc file can be stored anywhere you like: external SD card, USB‑OTG drive, a NAS, or a cloud backup service. Because it’s encrypted with a strong AES‑256 key, even if the storage medium is lost or stolen the photos remain unreadable.
When you need to restore the images:
.tar.enc file back to the device (or any Linux/Windows machine with OpenSSL).openssl enc -d -aes-256-cbc -in photos.tar.enc -out photos.tartar -xvf photos.tar -C ~/storage/shared/RestoredPhotosAfter extraction you can delete the intermediate photos.tar if you wish to keep the archive encrypted.
Using Termux and OpenSSL you can create a reliable, password‑protected backup of every photo on your Android device without rooting or third‑party apps. The workflow gives you full control over where the backup lives, how it’s encrypted, and how you verify its integrity. Keep the password safe, test decryption occasionally, and repeat the process whenever you add a substantial number of new pictures.









