<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Security on TripleZ&#39;s Blog</title>
    <link>https://blog.triplez.cn/tags/security/</link>
    <description>Recent content in Security on TripleZ&#39;s Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-cn</language>
    <lastBuildDate>Fri, 09 Feb 2018 16:42:22 +0000</lastBuildDate><atom:link href="https://blog.triplez.cn/tags/security/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>让你的 Git Commit 带上 GPG 签名</title>
      <link>https://blog.triplez.cn/posts/let-git-commit-brings-with-your-gpg-signature/</link>
      <pubDate>Fri, 09 Feb 2018 16:42:22 +0000</pubDate>
      
      <guid>https://blog.triplez.cn/posts/let-git-commit-brings-with-your-gpg-signature/</guid>
      <description>&lt;p&gt;让你的 git commits 更安全。&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>让你的 git commits 更安全。</p>
<h2 id="生成-gpg-key">生成 GPG Key</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt" id="hl-0-1"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-0-1">1</a>
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ gpg --gen-key
</span></span></code></pre></td></tr></table>
</div>
</div><p>生成时需要的信息：</p>
<ul>
<li>加密算法：选择 <code>RSA</code>；</li>
<li>密钥长度：<code>4096</code>；</li>
<li>有效时间：<code>1y</code>；</li>
<li>名字：<code>TripleZ</code> <del>其实随意</del>；</li>
<li>邮箱：<code>me@triplez.cn</code> 必须是 <code>GitHub</code> 认证过的邮箱；</li>
<li>注释：<code>Generate GPG for git commits.</code> <del>随意即可</del>。</li>
</ul>
<h2 id="查看-gpg-key">查看 GPG Key</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt" id="hl-1-1"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-1-1">1</a>
</span><span class="lnt" id="hl-1-2"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-1-2">2</a>
</span><span class="lnt" id="hl-1-3"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-1-3">3</a>
</span><span class="lnt" id="hl-1-4"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-1-4">4</a>
</span><span class="lnt" id="hl-1-5"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-1-5">5</a>
</span><span class="lnt" id="hl-1-6"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-1-6">6</a>
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ gpg --list-keys
</span></span><span class="line"><span class="cl">/home/triplez/.gnupg/pubring.gpg
</span></span><span class="line"><span class="cl">--------------------------------
</span></span><span class="line"><span class="cl">pub   4096R/2******4 2018-02-09 <span class="o">[</span>expires: 2019-02-09<span class="o">]</span>
</span></span><span class="line"><span class="cl">uid                  TripleZ <span class="o">(</span>Gen GPG <span class="k">for</span> git commits<span class="o">)</span> &lt;me@triplez.cn&gt;
</span></span><span class="line"><span class="cl">sub   4096R/0******E 2018-02-09 <span class="o">[</span>expires: 2019-02-09<span class="o">]</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h2 id="导出-gpg-公钥">导出 GPG 公钥</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt" id="hl-2-1"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-2-1">1</a>
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ gpg --armor --export 2******4
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p>哈希值要根据实际情况而定。</p>
</blockquote>
<h2 id="配置-git">配置 Git</h2>
<p>设置 <code>Git</code> 默认使用刚才生成的 <code>GPG Key</code> ：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt" id="hl-3-1"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-3-1">1</a>
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ git config --global user.signingkey 2******4
</span></span></code></pre></td></tr></table>
</div>
</div><p>提交 <code>commit</code> 并使用 <code>GPG Key</code> 签名：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt" id="hl-4-1"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-4-1">1</a>
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ git commit -S
</span></span></code></pre></td></tr></table>
</div>
</div><p>设置 <code>Git</code> 默认开启 <code>GPG Key</code> 签名：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt" id="hl-5-1"><a style="outline: none; text-decoration:none; color:inherit" href="#hl-5-1">1</a>
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ git config --global commit.gpgsign <span class="nb">true</span>
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p>设置默认开启签名之后就不需要在 <code>commit</code> 时再加 <code>-S</code> 参数啦！</p>
</blockquote>
<p>再试试提交代码到 <code>GitHub</code> 上，是不是在 <code>commit</code> 上多了一个 <code>Verified</code> 按钮 🎉</p>]]></content:encoded>
    </item>
    
  </channel>
</rss>
