Skip to content

Instantly share code, notes, and snippets.

@MattJermyWright
Last active October 30, 2019 08:53
Show Gist options
  • Save MattJermyWright/3b88e2349e91db5fe831f780dbef8fad to your computer and use it in GitHub Desktop.
Save MattJermyWright/3b88e2349e91db5fe831f780dbef8fad to your computer and use it in GitHub Desktop.
GPG Setup - Vanilla setup on a system

Starting Out:

  • Run the command gpg --expert --full-generate-key
  • Create a certified certificate
$ gpg --expert --full-generate-key

gpg (GnuPG) 2.2.4; Copyright (C) 2017 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
   (9) ECC and ECC
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (13) Existing key
Your selection? 8

Possible actions for a RSA key: Sign Certify Encrypt Authenticate
Current allowed actions: Sign Certify Encrypt

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? s

Possible actions for a RSA key: Sign Certify Encrypt Authenticate
Current allowed actions: Certify Encrypt

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? e

Possible actions for a RSA key: Sign Certify Encrypt Authenticate
Current allowed actions: Certify

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? Q
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: Matt Wright
Email address: [email protected]
Comment:
You selected this USER-ID:
    "Matt Wright <[email protected]>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key AAAAAAAAAAAAAAAAAAA marked as ultimately trusted
gpg: directory '/home/matt/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/matt/.gnupg/openpgp-revocs.d/9B000EEXXXXXXXXXXXXXXXXXXXXXXXXXXXX.rev'
public and secret key created and signed.

pub   rsa2048 2019-06-14 [C]
      9B000EEXXXXXXXXXXXXXXXXXXXXXXXXXXXX
uid                      Matt Wright <[email protected]>

Add Authentication Subkey

  • Run the command gpg --expert --edit-key KEYID, where KEYID is given in the previous step (above, it's AAAAAAAAAAAAAAAAAAA)
  • Use the addkey function,
  • Add an Authorization Key
  • Save and exit
$ gpg --expert --edit-key $KEYID
gpg (GnuPG) 2.2.4; Copyright (C) 2017 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Secret key is available.

gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
sec  rsa2048/XXXXXXXXXXXXXXXX
     created: 2019-06-14  expires: never       usage: C
     trust: ultimate      validity: ultimate
[ultimate] (1). Matt Wright <[email protected]>

gpg> addkey
Please select what kind of key you want:
   (3) DSA (sign only)
   (4) RSA (sign only)
   (5) Elgamal (encrypt only)
   (6) RSA (encrypt only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (12) ECC (encrypt only)
  (13) Existing key
Your selection? 8

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Sign Encrypt

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? s

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Encrypt

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? e

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions:

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? a

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Authenticate

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? q
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
Really create? (y/N) y
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.

sec  rsa2048/XXXXXXXXXXXXXXXX
     created: 2019-06-14  expires: never       usage: C
     trust: ultimate      validity: ultimate
ssb  rsa2048/YYYYYYYYYYYYYYYY
     created: 2019-06-14  expires: never       usage: A
[ultimate] (1). Matt Wright <[email protected]>

gpg> quit
Save changes? (y/N) y

Add GPG Key Keygrip for Authorization Subkey to the sshcontrol file

  • Add keygrip id to ~/.gnupg/sshcontrol - typically you can just echo the value and append it to the file.
$ gpg --with-keygrip -k
/home/matt/.gnupg/pubring.kbx
-----------------------------
pub   rsa2048 2019-06-14 [C]
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
      Keygrip = 229C27XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
uid           [ultimate] Matt Wright <[email protected]>
sub   rsa2048 2019-06-14 [A]
      Keygrip = 4232E99YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

$ echo 4232E99YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY >> ~/.gnupg/sshcontrol

Setup gpg-agent.conf file

  • Add contents to gpg-agent.conf file

Add Entries to the Bashrc / Bash_profile:

  • Add contents to Bash startup file
# Setup Environment
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
export GPG_TTY=`tty`
# Kill existing gpg-agent
gpgconf --kill gpg-agent
# Launch GPG Agent
gpgconf --launch gpg-agent
# Update startup TTY - REQUIRED on UBUNTU due to Systemd
echo "UPDATESTARTUPTTY" | gpg-connect-agent > /dev/null 2>&1
default-cache-ttl 600
max-cache-ttl 7200
enable-ssh-support
# For Terminal Only / supports curses
# pinentry-program /usr/bin/pinentry-tty
# For Mac, use Homebrew
# pinentry-program /Users/matt/homebrew/bin/pinentry-mac
# For Terminal Only / supports curses
pinentry-program /usr/bin/pinentry-curses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment