Generating a new GPG key

  1. Generate a GPG key pair
gpg --full-generate-key
  1. At the prompt, specify the kind of key you
    want, or press Enter to accept the default.
  2. At the prompt, specify the key size you want,
    or press Enter to accept the default.
  3. Enter the length of time the key should be
    valid. Press Enter to specify the default
    selection, indicating that the key doesn’t
    expire.
  4. Verify that your selections are correct.
  5. Enter your user ID information.
  6. Type a secure passphrase.
  7. Use the gpg —list-secret-keys —keyid-format=long
    command to list the long form of the GPG keys for
    which you have both a public and private key. A
    private key is required for signing commits or
    tags.
gpg --list-secret-keys --keyid-format=long
  1. From the list of GPG keys, copy the long form
    of the GPG key ID you’d like to use. In this
    example, the GPG key ID is 3AA5C34371567BD2:
$ gpg --list-secret-keys --keyid-format=long
/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid                          Hubot <hubot@example.com>
ssb   4096R/4BB6D45482678BE3 2016-03-10
  1. Paste the text below, substituting in the GPG
    key ID you’d like to use. In this example, the GPG
    key ID is 3AA5C34371567BD2:
gpg --armor --export 3AA5C34371567BD2
# Prints the GPG key ID, in ASCII armor format
  1. Copy your GPG key, beginning with
    -----BEGIN PGP PUBLIC KEY BLOCK----- and ending
    with -----END PGP PUBLIC KEY BLOCK-----.
  2. Add the GPG key to your GitHub account.