GnuPG in Termux – Encrypt, Decrypt and Sign Files

GnuPG is a popular command-line tool for encryption, decryption, and digital signatures. It can protect files with a password, create public and private key pairs, sign files, and verify signatures. You can install GnuPG in Termux and use simple commands to learn how file encryption and key management work on Android.

Here’s what you can do with GnuPG in Termux:

  • Encrypt and decrypt files.
  • Protect files with a password.
  • Create public and private key pairs.
  • Create digital signatures.
  • Verify digital signatures.
  • List public and secret keys.
  • View key fingerprints.
  • Import and export keys.
  • Create ASCII-armored files.
  • Generate revocation certificates.
  • Change key passphrases.

Install GnuPG in Termux

You only need one command to install GnuPG in Termux. Run the command below in the Termux terminal to install it.

Update Termux packages.

pkg update && pkg upgrade -y

Install GnuPG.

pkg install gnupg -y

Check the installed GnuPG version.

gpg --version

GnuPG is now installed and ready to use.

Usage Commands

After installing GnuPG, you can use the following commands to encrypt files, decrypt files, create keys, and work with digital signatures.

Show the GnuPG help menu.

gpg --help

Create a text file for testing.

echo "Hello from Termux" > message.txt

Encrypt a file with a password.

gpg -c message.txt

GnuPG will ask you to enter a passphrase. After encryption, a file named message.txt.gpg will be created.

Decrypt the encrypted file.

gpg -d message.txt.gpg

To save the decrypted content into a new file:

gpg -o decrypted.txt -d message.txt.gpg

Create a new GnuPG key pair.

gpg --generate-key

Follow the instructions shown in the terminal to create your key.

List public keys.

gpg --list-keys

List secret keys.

gpg --list-secret-keys

Show key fingerprints.

gpg --fingerprint

Create a digital signature for a file.

gpg --sign message.txt

Create a clear-text signature.

gpg --clear-sign message.txt

Create a detached signature.

gpg --detach-sign message.txt

Verify a signature.

gpg --verify message.txt.asc

Export a public key to an ASCII file.

gpg --armor --export YOUR_EMAIL > public-key.asc

Import a public or private key.

gpg --import public-key.asc

You can also use GnuPG’s short commands for common operations.

List keys.

gpg -k

List secret keys.

gpg -K

Create an ASCII-armored output.

gpg -a

Specify an output file.

gpg -o output.txt

Encrypt a file for a specific recipient.

gpg -e -r USER-ID message.txt

Sign and encrypt a file for a specific recipient.

gpg -se -r USER-ID message.txt

Generate a revocation certificate for a key.

gpg --generate-revocation

Run an operation without making changes.

gpg --dry-run

Use the following command to see the complete available command list:

gpg --help

GnuPG provides many other commands and options for advanced key management, encryption, signatures, and OpenPGP operations.

End Note

GnuPG is a useful command-line tool for learning about file encryption, digital signatures, and public-key cryptography. It provides many options for protecting files and managing keys from the Termux terminal.

SHARE THIS POST: