Risan Bagja

Setup OpenPGP on macOS

Install the GPG on macOS:

$ brew install gpg2

Generating GPG key:

gpg --gen-key

# Key type: [1] RSA and RSA (default)
# Key Size: 4096
# Key expiry: [0] key does not expire
# Enter passphrase

Use GPG Key with Github

Your GPG key id is the 17F7A59386F928AA:

$ gpg --list-secret-keys --keyid-format LONG
sec   4096R/17F7A59386F928AA 2017-03-23
uid                          Risan (Risan GPG Key) <[email protected]> 
ssb   4096R/9876543210ABCDEF 2016-03-10

Export our public key. Copy and paste our exported public key to our Github account.

$ gpg --armor --export [email protected]

Tell Git about our GPG key:

$ git config --global user.signingkey 17F7A59386F928AA

Set all commits to be signed by default:

$ git config --global commit.gpgsign true

If you used gpg2 from Homebrew, update the program:

$ git config --global gpg.program gpg2

Sign our commit:

$ git commit -S -m "Your Message."

Basic Commands

List public keys in your keyring:

$ gpg --list-keys

List private keys in your keyring:

$ gpg --list-secret-keys

Delete private key:

$ gpg --delete-secret-key "User Name"

Delete public key:

$ gpg --delete-key "User Name"

List the private key in LONG format:

$ gpg --list-secret-keys --keyid-format LONG

Export public key to be shared with the other:

# Print to console.
$ gpg --armor --export 17F7A59386F928AA

# Or you can use email address.
$ gpg --armor --export [email protected]

# Or export to file.
$ gpg --armor --export [email protected] > mypubkey.asc

Edit User Detail

Edit user detail:

$ gpg --edit-key 17F7A59386F928AA
gpg> adduid

How to Back up

How to back up our GPG keys:

$ mkdir ~/Desktop/gpg
$ cp ~/.gnupg/pubring.gpg ~/Desktop/gpg/pubring.gpg
$ cp ~/.gnupg/secring.gpg ~/Desktop/gpg/secring.gpg
$ cp ~/.gnupg/trustdb.gpg ~/Desktop/gpg/trustdb.gpg