Home/Engineer/Security Hardening/GPG Key Generation and Pract…
Security HardeningIntermediateubuntucentosmacosgpgencryptionpgp

GPG Key Generation and Practical File Encryption

How to generate a GPG key pair, encrypt and decrypt files, and apply symmetric encryption and signing in day-to-day work.

Contents
  1. What is GPG?
  2. Generating Keys
  3. File Encryption (Public-Key)
  4. Symmetric Encryption (Password-Based)
  5. Digital Signatures
  6. Exporting / Importing Keys

What is GPG?

GNU Privacy Guard. It uses public-key cryptography for file encryption, digital signatures, and email encryption.


Generating Keys

Bash
gpg --full-generate-key
# RSA 4096 or Ed25519 , 2y

gpg --list-keys
gpg --list-secret-keys --keyid-format LONG

File Encryption (Public-Key)

Bash
gpg --encrypt --recipient "admin@example.com" secret.txt
# → secret.txt.gpg

gpg --decrypt secret.txt.gpg > secret.txt

gpg --armor --encrypt --recipient "admin@example.com" secret.txt
# → secret.txt.asc

Symmetric Encryption (Password-Based)

Bash
gpg --symmetric --cipher-algo AES256 backup.tar.gz
gpg --decrypt backup.tar.gz.gpg > backup.tar.gz

Digital Signatures

Bash
gpg --detach-sign release.tar.gz
# → release.tar.gz.sig

gpg --verify release.tar.gz.sig release.tar.gz

gpg --sign --encrypt --recipient "admin@example.com" file.txt

Exporting / Importing Keys

Bash
gpg --armor --export "admin@example.com" > public.key
gpg --armor --export-secret-keys "admin@example.com" > private.key

gpg --import public.key
gpg --import private.key
#gpg#encryption#pgp#Security
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Topic-related official docs (auto-linked · not per-claim sources)OWASP documentation ↗

Questions & answers

Ask a question about this guide. We'll review and reply.