---
# System prepended metadata

title: GNU Privacy Guard

---

# GNU Privacy Guard

GNU Privacy Guard (GnuPG or GPG) is a completely free implementation of PGP. It allows users to encrypt and sign data communications and features a versatile key management system.

## Install

1. Install using Homebrew

```bash
brew install gnupg
```

2. Add GPG to `~/.zshrc`

```bash
if [ -r ~/.zshrc ]; then echo -e '\nexport GPG_TTY=$(tty)' >> ~/.zshrc; \
else echo -e '\nexport GPG_TTY=$(tty)' >> ~/.zprofile; fi
```

## Usage

### Generate a new key

1. Use the `--full-generate-key` flag to generate a new key.

```bash
gpg --full-generate-key
```

2. Follow the prompt to generate a new key.

3. Check the generated key

### List all keys

Public keys

```bash
gpg --list-keys --keyid-format=long
```

Private keys

```bash
gpg --list-secret-keys --keyid-format=long
```

- `--keyid-format=long` -- displays your key's id in long format.

### Import gpg keys

```bash
gpg --import [KEY-FILE]
```

<sup>*Importing public and private key file uses the same command.</sup>

- Replace `[KEY-FILE]` with the path to your key file.

### Export your gpg keys

Public key

```bash
gpg --export --armor [KEY-ID]
```

Private key

```bash
gpg --export-secret-key --armor [KEY-ID]
```

- These will export and print your keys in the terminal.
- You can use the redirector `>` operator to redirect the output to a file.

## What is GPG

GPG keys are broken down into two types: public and private.

- **Public keys** are used to encrypt data and verify signatures.
- **Private keys** are used to decrypt data and sign data.

## Next Steps

- [Pinentry-mac](/xvJej2bKQlqjiD_fAfJ7fw)

## References

- https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key
- https://linuxhint.com/export-import-keys-with-gpg/
