This guide covers installing GPG on various operating systems (Windows, macOS, and Linux), generating a new key pair using modern Elliptic Curve Cryptography (ECC), exporting your public key, encrypting and decrypting files using users’ public keys, and encryption best practices.
Note: Newer versions of GnuPG (2.2 and later) support ECC keys. It is recommended to use ECC (such as Curve25519 for encryption and EdDSA/Ed25519 for signing) instead of RSA for improved security and performance.
- Download the latest Gpg4win installer from the official website.
- Run the installer, accept the license agreement, and select the default components. This includes Kleopatra, a graphical user interface (GUI) for easy key management, encryption, and decryption tasks. Gpg4win is the recommended method for Windows as it provides a user-friendly experience without requiring command-line expertise.
-
If Homebrew is not installed, install it from https://brew.sh by opening Terminal and running the installation command provided on the site.
-
In Terminal, run:
brew install gnupgThis installs the latest GnuPG version, optimized for macOS.
-
Debian/Ubuntu-based distributions: Open Terminal and run:
sudo apt update && sudo apt install gnupg -
Fedora-based distributions: Open Terminal and run:
sudo dnf install gnupg2 -
Arch Linux-based distributions: Open Terminal and run:
sudo pacman -S gnupg
These methods ensure you get the most up-to-date and secure version from your distribution's repositories.
Modern GnuPG supports ECC keys, which are recommended over RSA for better security, smaller key sizes, and faster performance. We'll use curves like Curve25519 for encryption and Ed25519 for signing.
- Launch Kleopatra from the Start menu.
- Click File → New Certificate….
- Select Create a personal OpenPGP key pair and click Next.
- Enter your name, email address, and optionally a comment, then click Next.
- In Advanced Settings:
- Choose ECC for the key type.
- Select Curve25519 for encryption and Ed25519 for signing.
- Set a key expiration date (recommended: 2-3 years) or choose no expiration, then click Next.
- Enter a strong passphrase (at least 12 characters, mixing letters, numbers, and symbols) to protect your private key.
- Click Create to generate the key pair.
- Your new key will appear in the My Certificates tab.
-
Open Terminal.
-
Run:
gpg --expert --full-generate-key -
Follow the interactive prompts:
- Select (9) ECC and ECC for key types.
- Choose (1) Curve25519 for encryption and Ed25519 for signing (it may be the default).
- Enter a key expiration (e.g.,
2yfor 2 years, or0for no expiration). - Provide your user ID: real name, email, and optional comment.
- Enter a strong passphrase to secure your private key.
Your key pair is now generated and added to your GnuPG keyring.
The GnuPG keyring is a secure storage for your public and private keys. Your own key pair is automatically added during generation. For others' keys:
-
Windows (Kleopatra GUI): In Kleopatra, click File → Import Certificates…, select the public key file (e.g.,
.asc), and import it. It will appear under Other Certificates. -
macOS / Linux (CLI): Run:
gpg --import recipient_public_key.asc
This adds the key to your keyring for use in encryption.
GnuPG uses a "web of trust" model. By default, imported keys are untrusted. To establish trust:
- Verify the key's fingerprint with the owner via a secure channel (e.g., in-person or encrypted video call).
- Set Trust Level:
- Windows (Kleopatra): Right-click the imported key, select Certify…, confirm the fingerprint, and choose a certification level (e.g., "I have checked the fingerprint").
- macOS / Linux (CLI): Run
gpg --edit-key recipient@example.com, then typetrustand select a level (e.g., 5 for ultimate trust, but use cautiously—reserve ultimate for your own key).
- For your own key, it should already have ultimate trust. This helps validate chains of trust for secure communication.
-
Windows (Kleopatra): In Kleopatra, double-click your key under My Certificates to view details like fingerprint, algorithm (should show ECC), and expiration.
-
macOS / Linux (CLI): Run:
gpg --list-keys gpg --list-secret-keys
Look for your key ID, user info, and ECC indicators (e.g., ed25519 or cv25519).
- Create a test file: In a text editor, save "This is a test." as
test.txt. - Encrypt it to yourself (using your own public key):
- Windows (Kleopatra): Right-click
test.txtin File Explorer, select More GpgEX options → Encrypt, choose your key, and encrypt. - macOS / Linux (CLI): Run
gpg --encrypt --recipient your.email@example.com test.txt(producestest.txt.gpg).
- Windows (Kleopatra): Right-click
- Decrypt it:
- Windows (Kleopatra): Right-click
test.txt.gpg, select More GpgEX options → Decrypt/Verify, enter your passphrase. - macOS / Linux (CLI): Run
gpg --decrypt test.txt.gpg > decrypted_test.txt.
- Windows (Kleopatra): Right-click
- Verify the decrypted file matches the original. If successful, your keys work.
Share your public key (not private!) for others to encrypt files to you.
-
Windows (Kleopatra): Right-click your key in My Certificates, select Export…, save as
my_public_key.asc(ASCII-armored format). -
macOS / Linux (CLI): Run:
gpg --armor --export your.email@example.com > my_public_key.asc
First, import and trust the recipient's public key (see Section 3).
-
Windows (Kleopatra GUI): Right-click the file in File Explorer, select More GpgEX options → Encrypt, choose the recipient's key, and confirm.
-
macOS / Linux (CLI): Run:
gpg --encrypt --recipient recipient@example.com filename.txt
Produces filename.txt.gpg.
- Compress into an archive first (recommended for efficiency):
- Use built-in tools: On Windows/macOS, right-click files and zip; on Linux, run
zip archive.zip file1.txt file2.txt.
- Use built-in tools: On Windows/macOS, right-click files and zip; on Linux, run
- Encrypt the archive as above.
Test by decrypting (see next section) to ensure functionality.
Files encrypted to your public key require your private key and passphrase.
-
Windows (Kleopatra GUI): Right-click the
.gpgfile, select More GpgEX options → Decrypt/Verify, enter your passphrase. The decrypted file is saved automatically. -
macOS / Linux (CLI): Run:
gpg --decrypt filename.txt.gpg > decrypted_filename.txt
Or to view without saving: gpg --decrypt filename.txt.gpg.
Test by comparing to the original if possible.
Sometimes, we need to re-encrypt a file with new or different recipients' public keys.
Below shows how to take an existing foo.txt.gpg, decrypt it to the stdout, pipe it back to gpg, and encrypt for the same/new/different recipients:
gpg --output - --decrypt foo.txt.gpg |
gpg -e -r recip1@bar.com
-r recip2@bar.com
-r recip3@bar.com
-o newfoo.txt.gpg
Your private key is the only way to decrypt files sent to you—losing it means permanent data loss; compromising it allows others to decrypt your data or impersonate you.
- What "Safe" Means: Store privately on encrypted drives or hardware security modules (e.g., YubiKey). Never share it. Use a strong passphrase.
- Best Practices:
- Backup your private key: Export it (e.g.,
gpg --export-secret-keys --armor > private_key.asc) and store encrypted backups offline (e.g., on USB in a safe). - Avoid cloud storage unless encrypted.
- Revoke and replace if compromised (use
gpg --edit-keyto set revocation). - Use hardware tokens for extra security if advanced.
- Backup your private key: Export it (e.g.,
- Use Strong Passphrases: Complex, unique, and managed with a password manager.
- Regular Key Backups: Export and store securely as above.
- Set Key Expiration Dates: Renew before expiry to maintain access.
- Verify Public Keys: Always check fingerprints via trusted channels.
- Keep Software Updated: Run updates for GnuPG/Gpg4win to patch vulnerabilities.
- Secure Key Distribution: Use key servers (e.g.,
gpg --send-keys keyID) or direct sharing. - Encrypt Locally: Never send unencrypted sensitive data; encrypt before transmission.
- Handle Trust Carefully: Only certify keys after verification to build a secure web of trust.
This guide provides a comprehensive overview for setting up GPG on Windows (using the Gpg4win UI tool), macOS, and Linux with modern ECC encryption, managing keys, and securely encrypting/decrypting files while following best practices for encryption security.