Skip to content

Instantly share code, notes, and snippets.

@pishchalnikov
Last active November 3, 2020 07:41
Show Gist options
  • Save pishchalnikov/9d5f5debb32cba64b2fe37abd36e34e8 to your computer and use it in GitHub Desktop.
Save pishchalnikov/9d5f5debb32cba64b2fe37abd36e34e8 to your computer and use it in GitHub Desktop.
Signing commits with GPG
1. Install GPG for your operating system.
If your Operating System has gpg2 installed, replace gpg with gpg2 in
the following commands.
2. Generate the private/public key pair with the following command, which will
spawn a series of questions:
$ gpg --full-gen-key
3. The first question is which algorithm can be used. Select the kind you want
or press Enter to choose the default (RSA and RSA):
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
4. The next question is key length. We recommend to choose the highest value
which is 4096:
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 4096
Requested keysize is 4096 bits
5. Next, you need to specify the validity period of your key. This is something
subjective, and you can use the default value which is to never expire:
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) 0
Key does not expire at all
6. Confirm that the answers you gave were correct by typing y:
Is this correct? (y/N) y
7. Enter you real name, the email address to be associated with this key (should
match a verified email address you use in GitLab) and an optional comment
(press Enter to skip):
GnuPG needs to construct a user ID to identify your key.
Real name: Roman
Email address: roman@test.com
Comment:
You selected this USER-ID:
"Roman <roman@test.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
8. Pick a strong password when asked and type it twice to confirm.
9. Use the following command to list the private GPG key you just created:
$ gpg --list-secret-keys --keyid-format LONG <roman@test.com>
10. Copy the GPG key ID that starts with sec. In the following example, that's
28F2B64B5246B6CA:
sec rsa4096/32F2B65B9E1C3126 2019-04-01 [SC]
D5E4F29F3325DC0CDA8FFC8153F2B65B1546B3CA
uid [ultimate] Roman <roman@test.com>
ssb rsa4096/B7ABC0812E3021C0 2019-04-01 [E]
11. Export the public key of that ID (replace your key ID from the previous step):
$ gpg --armor --export 32F2B65B9E1C3126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment