Introduction
From GnuPG Official Website
A GPG key (GNU Privacy Guard key) is a cryptographic key used for:
- Encrypting and decrypting data – to ensure confidentiality.
- Signing data and verifying signatures – to ensure authenticity and integrity.
How it works (simple breakdown)
- You generate a GPG key pair: one public, one private.
- You:
- Encrypt with the recipient’s public key → only they can decrypt (with their private key).
- Sign with your private key → others can verify it’s from you (with your public key).
- Combined → only recipient can decrypt and also verify it’s from you.
Common GPG commands
Generate a new key
gpg --full-gen-keyOr, for quickstart:
gpg --gen-keyList your keys
To list keys in your public key ring:
gpg --list-keysTo list keys in your secret key ring:
gpg --list-secret-keysExport your public key
gpg --export --armor --output public-key.asc user-idImport someone else’s key
gpg --import public-key.ascEncryption and decryption
Encrypt a file
gpg --encrypt --recipient [email protected] file.txtOnly recipient, with his/her private key, can decrypt file.txt.
Decrypt file
gpg --output file.txt --decrypt file.txt.gpgMaintenance
Backup your private key
gpg --export-secret-keys --armor --output private-key.asc user-idImport backed up private key
gpg --import private-key.ascSignatures
Signatures are created using sender’s private key and are then verified using sender’s public key.
Sign a file
gpg --sign file.txtGenerated file.txt.sig contains both the compressed content of the original file file.txt and the signature in a binary format, but the file is not encrypted.
Clearsign a file or message
gpg --clearsign file.txtHere both the content of the original file file.txt and the signature are stored in human-readable form in file.txt.sig.
Make a detached signature
gpg --detach-sig file.txtHere the signature is stored in file.txt.sig, but the contents of file.txt are not stored in it.
Verify a signature
gpg --verify file.txt.sigWhere file.txt.sig is the signed file containing the signature you wish to verify.
Verify detached signature
When verifying detached signature, both data file and the signature file must be present.
gpg --verify file.txt.sigNote: file.txt must be present in the same directory.
Tips
- Use the OpenKeychain for similar purpose on Android.
- The nautilus-scripts has a set of actions including encryption related scripts to be available on Nautilus.