Skip to content

Instantly share code, notes, and snippets.

@cuylerstuwe
Forked from ankurk91/github_gpg_key.md
Last active February 16, 2019 09:13
Show Gist options
  • Save cuylerstuwe/3f9a539801db0508803d11628b59f8f6 to your computer and use it in GitHub Desktop.
Save cuylerstuwe/3f9a539801db0508803d11628b59f8f6 to your computer and use it in GitHub Desktop.
Github : Signing commits using GPG (Ubuntu/Mac)

Signing GitHub Commits Using GPG (Ubuntu/Mac)

Ubuntu Prerequisites

sudo apt-get install gpa seahorse

OSX Prerequisites

brew install gpg

Ubuntu/OSX Instructions

  1. gpg --gen-key

  2. gpg --list-secret-keys --keyid-format LONG

Output format example:

/home/username/.gnupg/secring.gpg
-------------------------------
sec   4096R/<LONG_KEY> 2016-08-11 [expires: 2018-08-11]
uid                          User Name <user.name@email.com>
ssb   4096R/62E5B29EEA7145E 2016-08-11
  1. Copy the characters taking the position of <LONG_KEY> in the above template. This string of characters will be used a couple of times in the next set of commands.

  2. Run these git commands, replacing <LONG_KEY> with the copied string of characters from above.

git config --global user.signingkey <LONG_KEY>
git config --global commit.gpgsign true
  1. Copy the characters in the place of <LONG_KEY> above into this command which outputs the GPG key to the clipboard:

gpg --armor --export <LONG_KEY> | pbcopy

NOTE: Replace pbcopy with xclip -sel clip or equivalent for whatever other clipboard utility might be installed when using Linux.

GitHub

  1. Navigate to Settings > Keys.
  2. Select New GPG Key, paste, and save.

Finish

NOTE: It's possible that you'll need to restart the gpg-daemon in order to get it to ask for the password. One way to do this (on OSX, at least) is pkill "gpg-agent" followed by gpg-agent --daemon.

Bonus

Remember GPG Password

Edit your ~/.gnupg/gpg-agent.conf file, pasting these two lines with <SECONDS> replaced:

default-cache-ttl <SECONDS>
max-cache-ttl <SECONDS>

Change GPG Password

gpg --edit-key <PASTE_YOUR_KEY_ID_HERE>

At the gpg prompt type passwd. Type in the current passphrase when prompted. Type in the new passphrase twice when prompted. Type: save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment