<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gers2017</title>
    <description>The latest articles on DEV Community by Gers2017 (@gers2017).</description>
    <link>https://dev.to/gers2017</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F605212%2F3d7013c8-4e36-4e03-977b-8ef9e210348e.png</url>
      <title>DEV Community: Gers2017</title>
      <link>https://dev.to/gers2017</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gers2017"/>
    <language>en</language>
    <item>
      <title>How to sign your commits with GPG or SSH keys</title>
      <dc:creator>Gers2017</dc:creator>
      <pubDate>Sat, 03 Sep 2022 13:27:43 +0000</pubDate>
      <link>https://dev.to/gers2017/how-to-sign-your-commits-with-gpg-or-ssh-keys-2cgi</link>
      <guid>https://dev.to/gers2017/how-to-sign-your-commits-with-gpg-or-ssh-keys-2cgi</guid>
      <description>&lt;h2&gt;
  
  
  Sign your Commits!!!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1kxdm5yn4bz8h14ghimm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1kxdm5yn4bz8h14ghimm.gif" alt="RUN" width="439" height="341"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2f8bga1a0eni8i1qz5a2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2f8bga1a0eni8i1qz5a2.gif" alt="Keep calm" width="275" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you happen to be a github user then you might have seen this &lt;strong&gt;Verified&lt;/strong&gt; signature next to some commits.&lt;/p&gt;

&lt;p&gt;What does it mean? Are they part of secret society of Verified users? should I be signing my commits too?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3blkej8axutqb17fsnr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3blkej8axutqb17fsnr.png" alt="Github Signed Commit" width="800" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's be real here, we all like shiny green badges next to our commits, it give us a sense of power.&lt;br&gt;
Good news! In this blog-post you're going to learn how to sign your commits using GPG or SSH keys.&lt;/p&gt;
&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Using GPG to sign commits&lt;/li&gt;
&lt;li&gt;Add GPG key to Github&lt;/li&gt;
&lt;li&gt;Configure Git to use GPG key&lt;/li&gt;
&lt;li&gt;Using SSH keys to Sign Commits&lt;/li&gt;
&lt;li&gt;Resources&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Using GPG to sign commits
&lt;/h2&gt;

&lt;p&gt;Before we get started, please check the version of &lt;code&gt;gpg&lt;/code&gt; is up to date by running &lt;code&gt;gpg --version&lt;/code&gt;&lt;br&gt;
Mine is &lt;code&gt;gpg (GnuPG) 2.2.37&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Generate the GPG key
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gpg &lt;span class="nt"&gt;--full-generate-key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;what kind of key you want: select RSA (sign only) by typing &lt;code&gt;4&lt;/code&gt; and hit &lt;code&gt;Enter&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;keysize: type &lt;code&gt;4096&lt;/code&gt; and hit &lt;code&gt;Enter&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;how long the key should be valid: recommended &lt;code&gt;2y&lt;/code&gt; or &lt;code&gt;3y&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer the questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Real name: Your name or your Github username&lt;/li&gt;
&lt;li&gt;Email address: The verified email address for your github account

&lt;ul&gt;
&lt;li&gt;Github specific: You could also use the no-reply email of your Github account: At &lt;a href="https://github.com/settings/emails" rel="noopener noreferrer"&gt;email settings&lt;/a&gt; bellow the &lt;code&gt;Keep my email addresses private&lt;/code&gt; checkbox should be the no-reply email like &lt;code&gt;@users.noreply.github.com&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Assuming everything is fine, type &lt;code&gt;O&lt;/code&gt; to confirm&lt;/li&gt;
&lt;li&gt;Provide a passphrase: Choose a secure passphrase

&lt;ul&gt;
&lt;li&gt;personal recommendation: create a passphrase made of &lt;code&gt;12&lt;/code&gt; to &lt;code&gt;16&lt;/code&gt; characters with at least one special character (&lt;code&gt;$, #, @, ...&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Test the GPG key
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'hi!'&lt;/span&gt; | gpg &lt;span class="nt"&gt;--clear-sign&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; test.txt
gpg &lt;span class="nt"&gt;--verify&lt;/span&gt; test.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It should say something like: &lt;code&gt;Good signature from "USERNAME (Test Key) &amp;lt;example@email.com&amp;gt;"&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Get the GPG key ID
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gpg &lt;span class="nt"&gt;--list-secret-keys&lt;/span&gt; &lt;span class="nt"&gt;--keyid-format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;long
&lt;span class="c"&gt;# or&lt;/span&gt;
gpg &lt;span class="nt"&gt;-K&lt;/span&gt; &lt;span class="nt"&gt;--keyid-format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;short

&lt;span class="c"&gt;# Output:&lt;/span&gt;

sec   rsa4096/A537823F 2022-09-02 &lt;span class="o"&gt;[&lt;/span&gt;SC] &lt;span class="o"&gt;[&lt;/span&gt;expires: 2023-09-02]
    E98E6B0663442DE0463E2A880FE0F073A537823F
uid         &lt;span class="o"&gt;[&lt;/span&gt;ultimate] USERNAME &lt;span class="o"&gt;(&lt;/span&gt;Test Key&lt;span class="o"&gt;)&lt;/span&gt; &amp;lt;example@email.com&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In this case the key ID is &lt;code&gt;A537823F&lt;/code&gt; (from &lt;code&gt;rsa4096/A537823F&lt;/code&gt;)&lt;/p&gt;
&lt;h3&gt;
  
  
  Add GPG key to Github
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Get the public key&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;gpg &lt;span class="nt"&gt;--armor&lt;/span&gt; &lt;span class="nt"&gt;--export&lt;/span&gt; A537823F

&lt;span class="c"&gt;# generated key&lt;/span&gt;
&lt;span class="c"&gt;# -----BEGIN PGP PUBLIC KEY BLOCK-----&lt;/span&gt;
&lt;span class="c"&gt;# ....&lt;/span&gt;
&lt;span class="c"&gt;# -----END PGP PUBLIC KEY BLOCK-----&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Copy the generated key&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Go to &lt;a href="https://github.com/settings/keys" rel="noopener noreferrer"&gt;SSH and GPG keys on github&lt;/a&gt; or &lt;a href="https://github.com/settings/gpg/new" rel="noopener noreferrer"&gt;Add new GPG key on github&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/managing-commit-signature-verification/adding-a-gpg-key-to-your-github-account" rel="noopener noreferrer"&gt;More details here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Paste the generated key&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Click &lt;code&gt;Add GPG key&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Configure Git to use GPG key
&lt;/h3&gt;

&lt;p&gt;With the key ID &lt;code&gt;A537823F&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Add signingkey&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.signingkey A537823F
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enable sign for all commits and tags&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; commit.gpgSign &lt;span class="nb"&gt;true
&lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; tag.gpgSign &lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set your name and email&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name USERNAME
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email example@email.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Gpg agent configuration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Export GPG_TTY&lt;br&gt;
append the following to your &lt;code&gt;.bashrc&lt;/code&gt; / &lt;code&gt;.zshrc&lt;/code&gt; or your initialization file&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;GPG_TTY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;tty&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# For fish users:&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; GPG_TTY &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;tty&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;ul&gt;
&lt;li&gt;Configure gpg.conf&lt;/li&gt;
&lt;li&gt;create &lt;code&gt;~/.gnupg/gpg.conf&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;append &lt;code&gt;use-agent&lt;/code&gt; to &lt;code&gt;~/.gnupg/gpg.conf&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Using SSH keys to Sign Commits
&lt;/h2&gt;

&lt;p&gt;If you don't have a ssh key already, check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent" rel="noopener noreferrer"&gt;Generating a new SSH key - Github Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account" rel="noopener noreferrer"&gt;Adding a new SSH key - Github Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Don't forget&lt;/strong&gt; to set the Key type to &lt;code&gt;Signing key&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you do have one, then:&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure git to use ssh
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; gpg.format ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Copy your public ssh key
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.ssh/id_ed25519.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Set the signkey to your public ssh key (replace the text inside the quotes)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Beware of the quotes&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.signingkey &lt;span class="s1"&gt;'ssh-ed25519 AAAAC3(...) example@email.com'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add your public ssh key to &lt;code&gt;~/.config/git/allowed_signers&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;example@email.com ssh-ed25519 ssh-ed25519 AAAAC3&lt;span class="o"&gt;(&lt;/span&gt;...&lt;span class="o"&gt;)&lt;/span&gt; example@email.com example@email.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let Git know about this file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verify your signed commit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Some message"&lt;/span&gt;

&lt;span class="c"&gt;# Verify the commit&lt;/span&gt;

git verify-commit 488a8d82 &lt;span class="c"&gt;# get the hash with git log&lt;/span&gt;
&lt;span class="c"&gt;# Or &lt;/span&gt;
git log &lt;span class="nt"&gt;--show-signature&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://withblue.ink/2020/05/17/how-and-why-to-sign-git-commits.html" rel="noopener noreferrer"&gt;How (and why) to sign Git commits&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.dbrgn.ch/2021/11/16/git-ssh-signatures/" rel="noopener noreferrer"&gt;Signing Git Commits with SSH Keys&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification" rel="noopener noreferrer"&gt;About signature verification - Github Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key" rel="noopener noreferrer"&gt;Tell git about your keys - Github Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent" rel="noopener noreferrer"&gt;Generate a new SSH key - Github Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://linux.die.net/man/1/gpg-agent" rel="noopener noreferrer"&gt;GPG agent&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://riseup.net/en/security/message-security/openpgp/best-practices" rel="noopener noreferrer"&gt;OpenPGP Best Practices&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>gpg</category>
      <category>security</category>
    </item>
  </channel>
</rss>
