「之岙」

「之岙」

How to add GPG to Github

Precondition#

The terminal gpg command is working properly

Generate GPG Key#

Note: It should be consistent with the email in git config, check the command below

git config --global user.email

Generate key

gpg --full-generate-key
  1. Select key type: default is fine
  2. Select algorithm: default
  3. Expiry: according to yourself
  4. Is this correct: y
  5. Name
  6. Email (make sure to use the one in git config)
  7. Comment: according to yourself
  8. Enter password
Get key information#
gpg --list-keys

The first line switch is pub, copy the id from the second line, then execute in the terminal:

gpg --armor --export copied id

Example: gpg --armor --export 4F113915706D141348CDC3DB5873563E6B2

After execution, you will get a public key starting with BEGIN and ending with END, copy it and go to github

Paste the public key into Github#

github->profile icon at the top right->setting->SSH and GPG keys->New GPG key

  1. Give it a Title
  2. Paste the copied content into Key
  3. Add GPG key
Sign Git commits with GPG private key#

Get the list of keys

gpg --list-keys

Copy the id

git config --global user.signingkey copied id

Example: git config --global user.signingkey 4F113915706D141348CDC3DB5873563E6B2

To sign each commit, add the -S parameter

git commit -S -m "..."

You can also automatically require signatures

git config --global commit.gpgsign true
Trust Github's own GPG key#

Purpose: When creating a repository on the web, if it doesn't show Verified, it can be frustrating for perfectionists

Import Github's own GPG key

curl https://github.com/web-flow.gpg | gpg --import

Github's key expired after 24 years, so two keys will be imported

Get the list of keys

gpg --list-keys

Copy the id of the Github key that hasn't expired, then perform the signing operation

gpg --sign-key 968479A1AFF927E37D1A566BB5690EEEBB952194

Enter y to confirm the signature.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.