GnuPG cheat sheet

Reference commands for gpg.
  1. PGP key management
    1. List
    2. Create
    3. Delete
    4. Import
    5. Export
    6. Distribute
  2. Credential caching
  3. Troubleshooting
  4. References

PGP key management

List

List the keys in your secret (private) key ring:

gpg --list-secret-keys

List the keys in your public key ring:

gpg --list-keys

Create

Create a new key:

gpg --gen-key

Delete

Delete a secret key from your key ring:

gpg --delete-secret-key "USER_NAME"

Delete a public key from your key ring:

gpg --delete-key "USER_NAME"

Import

Import a secret key:

gpg --allow-secret-key-import --import private.key

Import a public key:

gpg --import public.key

Export

Export a secret (private) key:

gpg --export-secret-key -a "USER_NAME" > private.key

Export a public key:

gpg --export -a "USER_NAME" > public.key

Distribute

Send (upload) a key to public keyserver:

gpg --keyserver keys.openpgp.org --send-key "EMAIL"

Receive a public key:

gpg --keyserver keys.openpgp.org --recv-key "KEY_ID"

Credential caching

GnuPG prompts frequently for password by default. Here’s how to relax this a little bit.

Add ~/.gnupg/gpg-agent.conf:

default-cache-ttl 10000000

Troubleshooting

Restart gpgconf:

gpgconf --kill all

Restart gpg-connect-agent:

gpg-connect-agent reloadagent /bye

Restart gpg-agent daemon:

pkill -9 gpg-agent
source <(gpg-agent --daemon)

References