Common configurations for GitHub
Official documentation here.
On Windows, do the following
-
From the official gnupg webpage, download gpg4win. Install the program.
-
Verify that the program is in your path by running
($ENV:Path).Replace(";","`n")
An entry like
C:\Program Files (x86)\Gpg4win\..\GnuPG\bin
will be in the path, allowing the discovery ofgpg.exe
-
Open
Kleopatra
and generate new key pair (Ctrl + N
or use GUI)Make sure you use the GitHub verified email address and set the expiration date accordingly
-
After the key is generated, verify it by running
gpg --list-secret-keys --keyid-format=long
The key ID under
sec
andssb
should match the subkey details in Kleopatra (double click on key -> more details) -
Copy the public key through Kleopatra
- Double click the key in Kleopatra
- Click Export and copy everything in the window, starting from
-----BEGIN PGP PUBLIC KEY BLOCK-----
and ending with-----END PGP PUBLIC KEY BLOCK-----
-
Open GitHub and go to GPG key settings, and add a GPG key. Paste the contents of the clipboard (from the previous step).
-
Configure the local
git
to sign commits be defaultSign commits using GPG by default
git config --global commit.gpgsign true
Set the path to the GPG program
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
That's it, try this with a test commit and see the Verified
badge beside it on GitHub 🎉
WIP: Not working currently for WSL
For WSL, do the following (assuming Ubuntu WSL)
-
Verify existing keys and program
gpg --list-secret-keys --keyid-format=long which gpg
The above should create a
~/.gnupg
folder -
Verify that
git
configurations do not already have something setupgit config --global -l
-
Generate a new key
Start the utility
gpg --full-generate-key
Select any algorithm (RSA works) and make sure the keysize is 4096. You may set a passphrase.
-
Get the key
List them all
gpg --list-secret-keys --keyid-format=long
Get a particular key (assuming ID - after
algo/
insec
line - is3AA5C34371567BD2
)gpg --armor --export 3AA5C34371567BD2
Copy the output to clipboard
-
Open GitHub and go to GPG key settings, and add a GPG key. Paste the contents of the clipboard (from the previous step).
-
Configure
git
locally to use gpgAutomatically sign commits
git config --global commit.gpgsign true
Set the path
git config --global gpg.program `which gpg`
Verify
git config --global -l