|
| 1 | +--- |
| 2 | +title: Verified Commits |
| 3 | +seoTitle: Quick guide for the impatient on how to use GPG and SSH to sign commits, on GitHub |
| 4 | +summary: Sign commits with SSH and GPG |
| 5 | +isReleased: true |
| 6 | +isSequel: false |
| 7 | +lastModDate: 2019-12-05T09:15:00-0401 |
| 8 | +firstModDate: 2019-12-05T09:15:00-0401 |
| 9 | +minutesToRead: 4 |
| 10 | +tags: |
| 11 | + - 'SSH' |
| 12 | + - 'GPG' |
| 13 | + - 'git' |
| 14 | +--- |
| 15 | +<C> |
| 16 | +*Guide for the impatient* |
| 17 | +</C> |
| 18 | +<H2>Only Using SSH To Sign Commits</H2> |
| 19 | +<C>First generate an SSH key, you must have ``ssh`` installed, to verify, run this</C> |
| 20 | +<Code |
| 21 | + code={`ssh -V |
| 22 | +`} |
| 23 | + language="shell" |
| 24 | + showLineNumbers={false} |
| 25 | +/> |
| 26 | +<C> |
| 27 | +You should get the version info, with no errors. |
| 28 | +</C> |
| 29 | +<C> |
| 30 | +To generate keys for GitHub specifically, here I'll save you some time, paste <L href="https://github.com/AshGw/dotfiles/blob/main/.ssh/_gh_gen.sh">this</L> in your terminal. |
| 31 | +</C> |
| 32 | +<C> |
| 33 | +This will will generate an SSH key pair, `ashgw` is my username, yours will be different. |
| 34 | +</C> |
| 35 | +<Code |
| 36 | + code={`Generating public/private ed25519 key pair. |
| 37 | +Created directory '/home/ashgw/.ssh'. |
| 38 | +Enter passphrase (empty for no passphrase):`} |
| 39 | + language="shell" |
| 40 | + showLineNumbers={false} |
| 41 | +/> |
| 42 | +<C> |
| 43 | +Optionally enter a key phrase, that's on you. |
| 44 | +</C> |
| 45 | +<Code |
| 46 | + code={`Your identification has been saved in /home/ashgw/.ssh/github |
| 47 | +Your public key has been saved in /home/ashgw/.ssh/github.pub |
| 48 | +The key fingerprint is: |
| 49 | +SHA256:A7vCUer8pc+IPmTOHS5ULS4hOXX4SElUA0lbVj9SbgI ashgw@ashx |
| 50 | +The key's randomart image is: |
| 51 | ++--[ED25519 256]--+ |
| 52 | +| +=*E.. . | |
| 53 | +| *+.o + | |
| 54 | +| +.+o.o = | |
| 55 | +| + oo+o.+ . | |
| 56 | +| oo+..S | |
| 57 | +| +=.o. . | |
| 58 | +| *=+... | |
| 59 | +| =+o= | |
| 60 | +| .oo+.o | |
| 61 | ++----[SHA256]-----+ |
| 62 | +Agent pid 3606 |
| 63 | +Identity added: /home/ashgw/.ssh/github (ashgw@ashx) |
| 64 | +➜ ~`} |
| 65 | + language="shell" |
| 66 | + showLineNumbers={false} |
| 67 | +/> |
| 68 | +<C> |
| 69 | +You should get the same output with no problems. |
| 70 | +Now if you run the command, while `xclip` is installed, the public key will be copied to your clipboard, if you don't have `xclip`, then manually copy it. |
| 71 | +</C> |
| 72 | +<Code |
| 73 | + code={`cat ~/.ssh/github.pub`} |
| 74 | + language="shell" |
| 75 | + showLineNumbers={false} |
| 76 | +/> |
| 77 | +<C>You should get the public key</C> |
| 78 | +<Code |
| 79 | + code={`➜ ~ cat ~/.ssh/github.pub |
| 80 | +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMoih/l+dazF/waAOFry1h0i5kT4+cislDxfFRreE2I2 ashgw@ashx |
| 81 | +➜ ~ `} |
| 82 | + language="shell" |
| 83 | + showLineNumbers={false} |
| 84 | +/> |
| 85 | +<H2>Where To Paste It?</H2> |
| 86 | +<C> |
| 87 | +Go <L href='https://github.com/settings/keys'>here</L>, Under SSH keys section, you'll find an "authentication keys" section as well as "signing key" section, paste your public key in **BOTH**. Before that works though, you need to modify your ``~/.gitconfig`` |
| 88 | +</C> |
| 89 | +<Code |
| 90 | + code={`[user] |
| 91 | + email = <YOUR_ACTUAL_VERIFIED_EMAIL_ON_GITHUB> |
| 92 | + name = <YOUR_NAME_CAN_BE_FAKE_THO> |
| 93 | + signingkey = /home/<YOUR_USERNAME_HERE>/.ssh/github.pub |
| 94 | +
|
| 95 | +# other stuff ...`} |
| 96 | + language="shell" |
| 97 | + showLineNumbers={false} |
| 98 | +/> |
| 99 | +<C> |
| 100 | +That's it. If you're wondering what else can be put inside ``~/.gitconfig`` you can checkout mine <L href='https://github.com/AshGw/dotfiles/blob/main/.gitconfig'>here</L>. Now your commits will be verified. |
| 101 | +</C> |
| 102 | +<H2>Connect With SSH, Sign With GPG</H2> |
| 103 | +<C> |
| 104 | +Do the steps above, then try to clone one of your repo's with `SSH`, if not problem occurs, you're good. Next, you must have `gpg` installed. You're probably on ``Debian``, here's how to cop it. |
| 105 | +</C> |
| 106 | +<Code |
| 107 | + code={`sudo apt update && install gnupg`} |
| 108 | + language="shell" |
| 109 | + showLineNumbers={false} |
| 110 | +/> |
| 111 | + |
| 112 | +<C> |
| 113 | +Verify with: |
| 114 | +</C> |
| 115 | + |
| 116 | +<Code |
| 117 | + code={`gpg -version `} |
| 118 | + language="shell" |
| 119 | + showLineNumbers={false} |
| 120 | +/> |
| 121 | + |
| 122 | +<C> |
| 123 | +Second, if you don't have a key laying around, generate a new one with: |
| 124 | +</C> |
| 125 | + |
| 126 | +<Code |
| 127 | + code={`gpg --full-generate-key`} |
| 128 | + language="shell" |
| 129 | + showLineNumbers={false} |
| 130 | +/> |
| 131 | + |
| 132 | +<C> |
| 133 | +If you've successfully generated your key, then if you list your keys with |
| 134 | +</C> |
| 135 | + |
| 136 | +<Code |
| 137 | + code={`➜ ~ gpg -k `} |
| 138 | + language="shell" |
| 139 | + showLineNumbers={false} |
| 140 | +/> |
| 141 | + |
| 142 | +<C> |
| 143 | +You should get something like this |
| 144 | +</C> |
| 145 | + |
| 146 | +<Code |
| 147 | + code={`➜ ~ gpg -k |
| 148 | +/home/ashgw/.gnupg/pubring.kbx |
| 149 | +------------------------------ |
| 150 | +pub rsa4096 2018-02-20 [SC] |
| 151 | + 79821E0224D34EC4969FF6A8E5168EE090AE80D0 |
| 152 | +uid [ultimate] Ashref Gwader (personal) <[email protected]> |
| 153 | +sub rsa4096 2018-02-20 [E] |
| 154 | +
|
| 155 | +➜ ~`} |
| 156 | + language="shell" |
| 157 | + showLineNumbers={false} |
| 158 | +/> |
| 159 | + |
| 160 | +<C> |
| 161 | +You see that large number? That's your key ID. Copy it and paste it in your ``~/.gitconfig`` file |
| 162 | +</C> |
| 163 | + |
| 164 | +<Code |
| 165 | + code={`[user] |
| 166 | + email = <SAME_AS_ABOVE> |
| 167 | + name = <SAME_AS_ABOVE> |
| 168 | + signingkey = <THAT_ID> |
| 169 | +[gpg] # mandatory |
| 170 | + program = gpg |
| 171 | +
|
| 172 | +[commit] # mandatory |
| 173 | + gpgsign = true |
| 174 | +
|
| 175 | +# other stuff...`} |
| 176 | + language="shell" |
| 177 | + showLineNumbers={false} |
| 178 | +/> |
| 179 | + |
| 180 | +<C> |
| 181 | +Next thing you need to export your public GPG key. |
| 182 | +</C> |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | +<Code |
| 187 | + code={`gpg --armor --export <THAT_KEY_ID> | xclip -selection clipboard`} |
| 188 | + language="shell" |
| 189 | + showLineNumbers={false} |
| 190 | +/> |
| 191 | + |
| 192 | + |
| 193 | +<C> |
| 194 | +If you have `xclip` installed you'll get it copied to your clipboard, else, just run this |
| 195 | +</C> |
| 196 | + |
| 197 | +<Code |
| 198 | + code={`gpg --armor --export <THAT_KEY_ID> `} |
| 199 | + language="shell" |
| 200 | + showLineNumbers={false} |
| 201 | +/> |
| 202 | + |
| 203 | +<C> |
| 204 | +You'll get your public key ID, it should start with |
| 205 | +</C> |
| 206 | +<Code |
| 207 | + code={`-----BEGIN PGP PUBLIC KEY BLOCK-----`} |
| 208 | + language="shell" |
| 209 | + showLineNumbers={false} |
| 210 | +/> |
| 211 | +<C> |
| 212 | +It's a long chain of characters, you can find mine <L href="https://github.com/ashgw.gpg">here</L>, yours will be there too if you use it to sign commits, at `https://github.com/<YOUR_USERNAME>.gpg`. |
| 213 | + |
| 214 | +Next, take the key you just copied and paste it <L href='https://github.com/settings/gpg/new'>here</L>, give the key a title so you don't forget it and paste the public key. |
| 215 | +That's it, your commits are now verified with your ``GPG`` key, while you're still able to use ``SSH`` with GitHub. |
| 216 | +</C> |
0 commit comments