Skip to content

Instantly share code, notes, and snippets.

@exalted
Last active November 6, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exalted/8253e67d6e740cbac73bfdc058ee0a3f to your computer and use it in GitHub Desktop.
Save exalted/8253e67d6e740cbac73bfdc058ee0a3f to your computer and use it in GitHub Desktop.

(Inspired by https://help.github.com/articles/generating-a-new-gpg-key/.)

Install Homebrew (we will use Homebrew package manager to install gpg utility).

ℹ️ You could also install https://gpgtools.org instead, but I have no experience with it; so this guide will assume you have Homebrew installed.

Install gpg using Homebrew:

brew install gpg

Generate a new key (the most interesting part):

gpg --full-generate-key

The command above ask you a series of questions. We suggest you answer those as follows:

  • Type of the key: RSA and RSA (default)
  • Length of the key: 4096
  • Expiration: Never
  • Name: Your full name
  • Email: you@example.com
  • Comment: Remind yourself for the purpose of this key
  • Passphrase: You can type anything you want here, but the idea is to make it long and complex enough. DO NOT FORGET YOUR PHRASE!
  • Done.

At this point you must have a new pair of public-private keys. (They're binary files located in ~/.gnupg, but it doesn't matter.)

The next step is to go copy your public key and hand it over to someone and here's how you do it:

List your keys:

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

Find the one (or possibly the only one) with the uid "Your full name (Remind yourself for the purpose of this key) you@example.com"

Find its "key id" which is a sequence of numbers and letters following sec rsa4096/. So, for instance, if your key looks like this:

# sec   rsa4096/6867755046FH7C4E 2017-09-18 [SC]
#       1D45E70AB5FDF2844324B62E6867755046FH7C4E
# uid                 Ali Servet Donmez (...) <you@example.com>
# ssb   rsa4096/999A5555X5DF6B6D 2017-09-18 [E]

... your "key id" in the example above would be 6867755046FH7C4E.

Print your public key in ASCII armor format (of course you have to use your "key id" in the example below):

gpg --armor --export 6867755046FH7C4E

You could either copy & paste the terminal output, or pipe the output to pbcopy then paste it somewhere, or redirect the output to a file with > foobar.

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