Skip to content

Instantly share code, notes, and snippets.

@moazmohamed20
Created May 11, 2024 11:10
Show Gist options
  • Save moazmohamed20/9d24c141b15bb79c9fbdab9d5fd70a2d to your computer and use it in GitHub Desktop.
Save moazmohamed20/9d24c141b15bb79c9fbdab9d5fd70a2d to your computer and use it in GitHub Desktop.

GPG Key

  • Generate GPG key.

    gpg --full-generate-key
  • At the prompt, specify the kind of key you want, or press Enter to accept the default.

  • At the prompt, specify the key size you want, or press Enter to accept the default.

  • Press Enter to specify the default selection, indicating that the key doesn't expire (Recommended).

  • Verify that your selections are correct, press y then Enter to continue.

  • Real name: Enter your github username.

  • Email address: Enter your github email address.

  • Comment: Leave it empty.

  • At the prompt, Change (N)ame, (C)ommen, (E)mail or (O)kay/(Q)uit?, press o then Enter to continue.

  • A dialog will open, Type a secure passphrase.

  • List the long form of the GPG keys.

    gpg --list-secret-keys --keyid-format=long
  • Copy the long form of the GPG key ID you'd like to use. In this example, the GPG key ID is 31533A0FAC2CF7FE.

    ~/.gnupg/pubring.kbx
    --------------------------------
    sec   rsa3072/31533A0FAC2CF7FE 2024-05-11 [SC]
          8BA189A369AAF7A460C6302931533A0FAC2CF7FE
    uid                 [ultimate] moazmohamed15@outlook.com
    ssb   rsa3072/B4BDC01CCDBE17F1 2024-05-11 [E]
  • Display the public key, Use the GPG key ID from previous step. In this example, the GPG key ID is 31533A0FAC2CF7FE.

    gpg --armor --export 31533A0FAC2CF7FE
  • Copy your GPG key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK----- and ending with -----END PGP PUBLIC KEY BLOCK-----.

    -----BEGIN PGP PUBLIC KEY BLOCK-----
    
    mQGNBGY/SMABDADwo3vnm5PR4Jw4XOFNSC385S4D2EgbneJntTpKi1V9IeqfXyRm
    3B5jtXThTVpC6+UinoT3jiKeJpYydqXtdt87TvhNl7MulXOo6Sur4Kl08WPj7af3
    ...
    b2VJWLv6/T8dZcDJMBkJ+TpNahSQmSbevqpSEeTg/PrP1xs5Z/GX39fT8cdRP7sY
    I+z0NTU=
    =Tu6A
    -----END PGP PUBLIC KEY BLOCK-----
  • Paste GPG key to GitHub at:

    GitHub -> Settings -> SSH ang GPG keys -> New GPG key

Tip

To configure Git to sign all commits by default, enter the following command: verified-commit

git config --global user.signingkey 31533A0FAC2CF7FE
git config --global --unset gpg.format
git config --global commit.gpgsign true
git config --global tag.gpgsign true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment