PGP/GPG Key Generation
Demo OnlyPGP keys should always be generated locally using GPG. This page provides guidance for secure key generation and management.
Never generate PGP keys online
PGP private keys contain your cryptographic identity and must be generated on your local machine. A compromised private key allows attackers to decrypt your messages and forge your digital signature.
Use GnuPG (GPG) on your local system to generate keys securely.
Install GPG
macOS (Homebrew)
brew install gnupgDebian/Ubuntu
sudo apt install gnupgFedora/RHEL
sudo dnf install gnupg2Generate a Key Pair
Interactive key generation (recommended)
gpg --full-generate-keyQuick Ed25519 key generation
gpg --quick-generate-key 'Your Name <[email protected]>' ed25519 certQuick RSA 4096-bit key
gpg --quick-generate-key 'Your Name <[email protected]>' rsa4096 certKey type recommendations
- Ed25519/Curve25519: Modern, fast, and secure. Best for new keys.
- RSA 4096: Widely compatible. Use for maximum interoperability.
- Key expiration: Set to 1-2 years, can be extended later.
View & Export Keys
List all public keys
gpg --list-keysList your private keys
gpg --list-secret-keysExport public key (ASCII)
gpg --armor --export [email protected]Export public key to file
gpg --armor --export [email protected] > publickey.ascBackup private key (keep secure!)
gpg --armor --export-secret-keys [email protected] > privatekey.ascExample Public Key
Your exported public key will look similar to this:
-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEZQxxxxxBCADxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzQ
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
=xxxx
-----END PGP PUBLIC KEY BLOCK-----Publish to Key Server
Upload to default key server
gpg --send-keys YOUR_KEY_IDUpload to keys.openpgp.org
gpg --keyserver hkps://keys.openpgp.org --send-keys YOUR_KEY_IDConfigure Git Signing
Find your key ID
gpg --list-secret-keys --keyid-format=longSet signing key
git config --global user.signingkey YOUR_KEY_IDEnable automatic signing
git config --global commit.gpgsign true[user]
name = Your Name
email = [email protected]
signingkey = YOUR_KEY_ID
[commit]
gpgsign = true
[gpg]
program = gpgPGP key best practices
- Always use a strong passphrase for your private key
- Create a secure backup of your private key and revocation certificate
- Set a reasonable expiration date (1-2 years) and extend as needed
- Use subkeys for everyday tasks; keep your primary key offline
- Create a revocation certificate immediately after key generation
- Consider using a hardware security key (YubiKey, etc.) for enhanced security