Skip to content

Instantly share code, notes, and snippets.

@pulsejet
Last active November 29, 2020 06:13
Show Gist options
  • Save pulsejet/ce30cca99d24e3698a41f13245b1169e to your computer and use it in GitHub Desktop.
Save pulsejet/ce30cca99d24e3698a41f13245b1169e to your computer and use it in GitHub Desktop.
GPG PGP with git

Generate

# generate initial key
gpg --full-generate-key
gpg --list-secret-keys --keyid-format LONG  # get ID (sec)
gpg --armor --export 3AA5C34371567BD2  # get pubkey

# add identity
gpg --edit-key 3AA5C34371567BD2
$ gpg> adduid
gpg --armor --export 3AA5C34371567BD2  # get pubkey again

Backup

$ gpg --export-secret-keys --armor 3AA5C34371567BD2 > pgp_secret.asc
$ gpg --export-ownertrust > pgp_trustdb_backup.txt

Restore

$ gpg —-import pgp_secret.asc

# If you get a strange error, also try
$ cat pgp_secret.asc | gpg --with-colons --import

# Will delete the existing trust database.
$ rm ~/.gnupg/trustdb.gpg
$ gpg --import-ownertrust < pgp_trustdb_backup.txt

# Trust your own key if not restoring trust database
$ gpg --edit-key 3AA5C34371567BD2
$ gpg> trust # choose "ultimate" or other trust level
$ gpg> save # save the changes

Use key for Git

$ git config --global user.signingkey 3AA5C34371567BD2

# Auto-sign all commits globaly
$ git config --global commit.gpgsign true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment