DEV Community

Stephano Kambeta
Stephano Kambeta

Posted on

How to Use GPG to Encrypt Files in Termux

If you need a simple yet strong way to secure your files on Android, GPG (GNU Privacy Guard) is one of the best options. By using Termux, you can encrypt and decrypt files directly from your phone without transferring them to a computer. In this guide, we’ll walk through the installation, setup, and usage of GPG in Termux so you can protect sensitive information anywhere.

Why Use GPG in Termux?

GPG is widely used for secure file encryption and digital signatures. It’s trusted by developers, security experts, and privacy enthusiasts worldwide. When combined with Termux, you can encrypt files on the go — whether it’s personal notes, work documents, or backups — without relying on third-party apps that may compromise your data.

Installing GPG in Termux

To get started, open Termux and update your packages before installing GPG:

pkg update && pkg upgrade -y
pkg install gnupg -y

Enter fullscreen mode Exit fullscreen mode

This installs the GPG package and its dependencies, making it ready for encryption tasks.

Generating a GPG Key

If you don’t already have a GPG key, you’ll need to create one:

gpg --full-generate-key

Enter fullscreen mode Exit fullscreen mode

During the process, GPG will ask you to:

  • Select the key type (RSA is recommended)
  • Choose the key size (2048 or 4096 bits for better security)
  • Set an expiration date (optional)
  • Enter your name and email address
  • Create a strong passphrase

Encrypting a File

Once your key is ready, you can encrypt a file for yourself or for a specific recipient. For example, to encrypt a file named notes.txt for your own GPG key:

gpg -e -r "Your Name" notes.txt

Enter fullscreen mode Exit fullscreen mode

This creates a file named notes.txt.gpg which is unreadable without your private key.

Decrypting a File

To decrypt the encrypted file, use:

gpg -d notes.txt.gpg > notes.txt

Enter fullscreen mode Exit fullscreen mode

You’ll be prompted for your passphrase before GPG restores the file to its original content.

Exporting and Importing Keys

If you want to share your public key so others can send you encrypted files:

gpg --export -a "Your Name" > public.key

Enter fullscreen mode Exit fullscreen mode

To import someone else’s public key:

gpg --import public.key

Enter fullscreen mode Exit fullscreen mode

Practical Tips for Using GPG in Termux

More Resources

Expand your cybersecurity knowledge with these guides:

Conclusion

GPG in Termux makes file encryption portable, reliable, and straightforward. You don’t need root access or a PC to protect your sensitive files — just a few commands in Termux can keep your data safe from prying eyes. For further exploration of Termux tools and cybersecurity, browse the full Terminal Tools archive.

Top comments (0)