Intro to GPG |
Links | RSS | |
Author | ArgentumCation | Posts | Notes |
---|---|---|---|
License | CC-BY-NC-SA 4.0+ | Updated |
Paraphrasing from the Arch Wiki, GPG is basically an implementation of PGP (Pretty Good Privacy)/ RFC 4880. You can use it to sign stuff, encrypt stuff, and authenticate yourself (eg over SSH or S/MIME).
Generate Master Key
This is the key you’ll use to create subkeys. As such you’ll want to keep this safe somewhere
|
|
Next, we want to disable signing, since we’ll only use this key to make more keys (i.e. we’ll be certifying other keys)
|
|
Please select which elliptic curve you want:
(1) Curve 25519 *default*
(2) Curve 448
(3) NIST P-256
(4) NIST P-384
(5) NIST P-521
(6) Brainpool P-256
(7) Brainpool P-384
(8) Brainpool P-512
(9) secp256k1
Your selection?
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) 1y
Key expires at Tue Sep 24 21:26:26 2024 UTC
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: Mira Velturu
Email address: [email protected]
Comment: GPG Demo
You selected this USER-ID:
"Mira Velturu (GPG Demo) <[email protected]>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
After this, you’ll see something like:
gpg: revocation certificate stored as '/home/mira/.local/share/gnupg/openpgp-revocs.d/6AEDC0D9AD76A6DD613C884958C90C69DF7F1AF9.rev'
public and secret key created and signed.
pub ed25519 2023-09-25 [C] [expires: 2024-09-24]
6AEDC0D9AD76A6DD613C884958C90C69DF7F1AF9
uid Mira Velturu (GPG Demo) <[email protected]>
The revocation cert lets you mark this key as invalid in case it gets leaked or something similar, keep this safe
Double check to make sure the output contains [C]
and no other letters between the braces
Alright now time to add subkeys so we can Sign/Authenticate/Encrypt stuff
First we’ll add a subkey for signing and authentication
|
|
gpg --list-keys
Now we add a subkey, the process is pretty similar to how we made the master key
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
(14) Existing key from card
Your selection? 11
Possible actions for this ECC key: Sign Authenticate
Current allowed actions: Sign
(S) Toggle the sign capability
(A) Toggle the authenticate capability
(Q) Finished
Your selection? A
Possible actions for this ECC key: Sign Authenticate
Current allowed actions: Sign Authenticate
(S) Toggle the sign capability
(A) Toggle the authenticate capability
(Q) Finished
Your selection? Q
Please select which elliptic curve you want:
(1) Curve 25519 *default*
(2) Curve 448
(3) NIST P-256
(4) NIST P-384
(5) NIST P-521
(6) Brainpool P-256
(7) Brainpool P-384
(8) Brainpool P-512
(9) secp256k1
Your selection?
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) 1y
Key expires at Tue Sep 24 21:55:51 2024 UTC
Is this correct? (y/N) y
Really create? (y/N) y
gpg> save
Your output will look something like:
sec ed25519/58C90C69DF7F1AF9
created: 2023-09-25 expires: 2024-09-24 usage: C
trust: ultimate validity: ultimate
ssb ed25519/2A7D7227C6F75FF1
created: 2023-09-25 expires: 2024-09-24 usage: SA
[ultimate] (1). Mira Velturu (GPG Demo) <[email protected]>
We’ll need to do this process one more time to create an encryption subkey
|
|
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
(14) Existing key from card
Your selection? 12
Please select which elliptic curve you want:
(1) Curve 25519 *default*
(2) Curve 448
(3) NIST P-256
(4) NIST P-384
(5) NIST P-521
(6) Brainpool P-256
(7) Brainpool P-384
(8) Brainpool P-512
(9) secp256k1
Your selection?
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) 1y
Key expires at Tue Sep 24 22:03:43 2024 UTC
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 ed25519/58C90C69DF7F1AF9
created: 2023-09-25 expires: 2024-09-24 usage: C
trust: ultimate validity: ultimate
ssb ed25519/2A7D7227C6F75FF1
created: 2023-09-25 expires: 2024-09-24 usage: SA
ssb cv25519/2AD22394690453C2
created: 2023-09-25 expires: 2024-09-24 usage: E
[ultimate] (1). Mira Velturu (GPG Demo) <[email protected]>
gpg> save
Okay now you have a key, lets make it work with SSH now
|
|
Now you’re gonna need to set SSH_AUTH SOCK
so that we use gpg-agent
instead of ssh-agent
for handling SSH credentials (don’t worry this won’t mess with your existing SSH credentials)
Add the following to your .bashprofile
or .zshrc
To use your keys for SSH Auth we’ll need to add it to the sshcontrol file
|
|
echo 25F5E8427F0F9338A00F98225D125C09EAEBFF24 >> ~/.local/share/gnupg/sshcontrol
run ssh-add -l
to verify
Back up your keys and yeet the master key
Okay this one’s pretty simple:
|
|
doc
using your private key and the public keys of your recipients
|
|
doc.gpg
if you have a matching private keyEven easier, no keys required
|
|
doc
using a pre-shared keyDon’t @ me I know this isn’t actually encryption, but being able to provide signatures is important since it’ll show a) the file comes from you, and b) the file hasn’t been tampered with or corrupted
|
|
doc.sig
will be a binary blobdoc
readable in doc.sig
use --clearsign
instead of --sign
|
|
doc.sig
which you can send to someone alongside doc
As for verifying signatures, just do
|
|
If this is a detached signature, make sure doc
is in the same folder
.gpg
if they are binary data, or .asc
if stored with ASCII Armor (which is basically just base64)$ gpg --list-keys
: list pubkeys in your keyring$ gpg --list-secret-keys
: list private keys in your keyring$ gpg --export --armor --output public-key.asc [email or key ID]
: output your pubkey$ gpg --import public-key.asc
: import a pubkey$ gpg --gen-revoke --armor --output revcert.asc [email or key ID]
: output your revocation key$ gpg --keyserver keyserver.ubuntu.com --send-keys [key ID]
: to send your public key to the ubuntu keyserver
no pinentry
--pinentry=loopback
as a flag for gpggpg-agent.conf
TODO
cause pinentry is its own mess