Install the GPG on macOS:
$ brew install gpg2Generating GPG key:
gpg --gen-key
# Key type: [1] RSA and RSA (default)# Key Size: 4096# Key expiry: [0] key does not expire# Enter REAL NAME, EMAIL and COMMENT# Enter passphraseUse GPG Key with Github
Your GPG key id is the 17F7A59386F928AA:
$ gpg --list-secret-keys --keyid-format LONG/Users/risan/.gnupg/secring.gpg------------------------------------sec 4096R/17F7A59386F928AA 2017-03-23uid Risan (Risan GPG Key) <risanbagja@gmail.com>ssb 4096R/9876543210ABCDEF 2016-03-10Export our public key. Copy and paste our exported public key to our Github account.
$ gpg --armor --export risanbagja@gmail.comTell Git about our GPG key:
$ git config --global user.signingkey 17F7A59386F928AASet all commits to be signed by default:
$ git config --global commit.gpgsign trueIf you used gpg2 from Homebrew, update the program:
$ git config --global gpg.program gpg2Sign our commit:
$ git commit -S -m "Your Message."Basic Commands
List public keys in your keyring:
$ gpg --list-keysList private keys in your keyring:
$ gpg --list-secret-keysDelete 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 LONGExport public key to be shared with the other:
# Print to console.$ gpg --armor --export 17F7A59386F928AA
# Or you can use email address.$ gpg --armor --export risanbagja@gmail.com
# Or export to file.$ gpg --armor --export risanbagja@gmail.com > mypubkey.ascEdit User Detail
Edit user detail:
$ gpg --edit-key 17F7A59386F928AAgpg> adduidHow 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