Many Android users need a reliable way to protect sensitive documents, logs, or configuration files before sharing them. While encrypted ZIP files are convenient, they lack strong cryptographic guarantees and key management. GnuPG (GPG) offers OpenPGP‑compatible encryption, digital signatures, and a mature key‑ring system, and it runs perfectly inside Termux – a lightweight Linux environment that works on any unrooted Android device.
~/.gnupg directory if you have used GPG on this device before.Enter after each line.pkg update && pkg upgrade -y
This ensures you get the latest gnupg build.
pkg install gnupg
gnupg package includes gpg, gpg-agent, and related utilities.gpg --full-generate-key
1 and Enter.4096 and press Enter.2y (or 0 for never) and confirm.rngd utility (optional). Once completed, you’ll see a key fingerprint like:
pub rsa4096 2023-01-01 [SC]
3A5F 9C2D 7E8B 1F4A 6D3E 9A2B C4D5 E6F7 8A9B C0D1
gpg --armor --export your.email@example.com > ~/mykey.asc
mykey.asc now resides in Termux’s home directory (/data/data/com.termux/files/home). Use the Android share sheet to send it:
termux-share -a send -c text/plain -f ~/mykey.asc
This opens the standard Android share dialog, letting you email, message, or upload the key.
.asc file, save it to a location accessible from Termux (e.g., Downloads).termux-setup-storage
Accept the permission prompt.
gpg --import /sdcard/Download/contact_key.asc
gpg --list-keys
/sdcard/Download/secret.txt.gpg --output /sdcard/Download/secret.txt.gpg \
--encrypt --recipient contact@example.com /sdcard/Download/secret.txt
secret.txt.gpg. The original secret.txt remains unchanged; you may delete it if you no longer need an unencrypted copy.
--armor to create a text‑based .asc file that can be sent via email without binary attachment issues.message.gpg and saved it to /sdcard/Download, decrypt with:
gpg --output /sdcard/Download/message.txt \
--decrypt /sdcard/Download/message.gpg
message.txt.--armor option, the file will have a .asc extension. Decrypt it the same way; GPG automatically detects the format.report.txt.asc:
gpg --verify /sdcard/Download/report.txt.asc
Good signature from …. A warning indicates a missing or untrusted key.For frequent encryption, create a tiny shell script in ~/bin (make the folder if it doesn’t exist):
mkdir -p ~/bin
cat > ~/bin/enc <<'EOF'
#!/data/data/com.termux/files/usr/bin/sh
# Usage: enc recipient file
RECIPIENT=$1
FILE=$2
OUT="${FILE}.gpg"
if [ -z "$RECIPIENT" ] || [ -z "$FILE" ]; then
echo "Usage: enc recipient_email /path/to/file"
exit 1
fi
gpg --output "$OUT" --encrypt --recipient "$RECIPIENT" "$FILE"
echo "Encrypted to $OUT"
EOF
chmod +x ~/bin/enc
Now you can run:
enc contact@example.com /sdcard/Download/report.pdf
The script saves you from typing the long gpg command each time.
rng-tools:
pkg install rng-tools
rngd -r /dev/urandom
Then restart the key generation.
termux-setup-storage and granted the storage permission. Re‑launch Termux after granting.
.gpg. Prefer the ASCII‑armored .asc format for unreliable channels.
gpg --export-secret-keys --armor your.email@example.com > ~/backup_private.asc
Store the backup in a password‑protected archive (e.g., 7z) and keep it offline.
gpg --output revoke.asc --gen-revoke your.email@example.com
Publish the revocation to your keyservers.
If you prefer a graphical interface, the OpenKeychain app provides similar OpenPGP functionality without the command line. However, Termux gives you full control, scripting ability, and a consistent experience across Android versions.
By installing gnupg inside Termux you gain a portable, standards‑compliant encryption suite that works on any unrooted Android phone. The steps above cover key creation, sharing, encryption, decryption, and basic automation, all while keeping your private key safely encrypted with a strong passphrase. With the optional backup and revocation procedures, you can trust the workflow for personal documents, confidential work files, or any data that deserves end‑to‑end protection.









