GPG - GNU Privacy Guard
π« Caution
Never delete a GPG key once it has been added to GitHub.
# For macOS
brew install gpg
# For Linux (Debian/Ubuntu)
sudo apt install gnupg
# For Windows, use Gpg4win or install GPG via Chocolatey
choco install gnupg
gpg --full-generate-key
Please select what kind of key you want:
(1) RSA and RSA
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(9) ECC (sign and encrypt) *default*
(10) ECC (sign only)
(14) Existing key from card
Your selection? 1
---
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096
---
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) ENTER
---
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: Piotr Kowalski
Email address: [email protected]
Comment:
---
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Please enter the passphrase to β
β protect your new key β
β β
β Passphrase: ________________________________________ β
β β
β <OK> <Cancel> β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Choose: <OK>
(leave BLANK for NO password)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β You have not entered a passphrase - this is in general a bad idea! β
β Please confirm that you do not want to have any protection on your key. β
β β
β <Yes, protection is not needed> <Enter new passphrase> β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Choose: <Yes, protection is not needed>
Display the list of GPG keys:
gpg --list-secret-keys --keyid-format=long
Users/piecioshka/.gnupg/pubring.kbx
-----------------------------------
sec rsa4096/[__COPY_FROM_HERE__] 2022-06-06 [SC]
EC1036E157E5A858FCD268AFCCDF12FB69501BC5
uid [ultimate] Piotr Kowalski <[email protected]>
ssb rsa4096/5BF0C308E8DADEBB 2022-06-06 [E]
Display the public content of a specific GPG key:
gpg --armor --export [__AND_PASTE_HERE__]
gpg --verify
If you see the message:
gpg: Signature made Mon 06 Jun 2022 12:00:00 PM UTC
gpg: using RSA key [__COPY_FROM_HERE__]
gpg: Good signature from "Piotr Kowalski <[email protected]>"
then everything is set up correctly.
## Set the GPG program for Git
git config --global gpg.program "$(which gpg)"
## Set the GPG key for Git
git config --global user.signingkey GPG_KEY_ID
## Enable commit signing by default
git config --global commit.gpgsign true
## Enable tag signing by default
git config --global tag.gpgsign true