<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Toby Chung]]></title><description><![CDATA[Toby Chung]]></description><link>https://dev.tobychung.com</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 07:54:21 GMT</lastBuildDate><atom:link href="https://dev.tobychung.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Windows 上使用 SSH 签名 Git 提交记录]]></title><description><![CDATA[前提
生成新 SSH 密钥并复制
ssh-keygen -t ed25519 -C "your_email@example.com"

clip < ~/.ssh/id_ed25519.pub

将结果添加到 GitHub 的 SSH and GPG keys 中。
将 SSH 密钥添加到 ssh-agent

确保 ssh-agent 正在运行

eval "$(ssh-agent -s)"


将 SSH 私钥添加到 ssh-agent

ssh-add ~/.ssh/id_ed25519
...]]></description><link>https://dev.tobychung.com/signing-git-commits-with-ssh-keys</link><guid isPermaLink="true">https://dev.tobychung.com/signing-git-commits-with-ssh-keys</guid><category><![CDATA[CSS]]></category><category><![CDATA[Python]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Toby Chung]]></dc:creator><pubDate>Thu, 15 Sep 2022 14:20:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1649662225945/7f_c6UxhR.jpg?auto=compress" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-5ymn5oq">前提</h2>
<h3 id="heading-ssh">生成新 SSH 密钥并复制</h3>
<pre><code class="lang-bash">ssh-keygen -t ed25519 -C <span class="hljs-string">"your_email@example.com"</span>
</code></pre>
<pre><code class="lang-bash">clip &lt; ~/.ssh/id_ed25519.pub
</code></pre>
<p>将结果添加到 GitHub 的 SSH and GPG keys 中。</p>
<h3 id="heading-ssh-ssh-agent">将 SSH 密钥添加到 ssh-agent</h3>
<ul>
<li>确保 ssh-agent 正在运行</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-built_in">eval</span> <span class="hljs-string">"<span class="hljs-subst">$(ssh-agent -s)</span>"</span>
</code></pre>
<ul>
<li>将 SSH 私钥添加到 ssh-agent</li>
</ul>
<pre><code class="lang-bash">ssh-add ~/.ssh/id_ed25519
</code></pre>
<h2 id="heading-ssh">使用 SSH 签名</h2>
<ul>
<li>全局使用 SSH 签名</li>
</ul>
<pre><code class="lang-bash">git config --global gpg.format ssh
</code></pre>
<ul>
<li>指定 SSH 签名使用文件</li>
</ul>
<pre><code class="lang-bash">git config --global user.signingKey ~/.ssh/id_ed25519.pub
</code></pre>
<ul>
<li>在 .ssh 目录新建一个可信公钥列表文件 <code>allowed_signers</code>, 内容为 <code>id_ed25519.pub</code> 前面加上邮箱</li>
</ul>
<pre><code class="lang-bash">touch ~/.ssh/allowed_signers &amp;&amp; clip &lt; ~/.ssh/id_ed25519.pub
</code></pre>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"your_email@example.com 粘贴到这"</span> &gt;&gt; ~/.ssh/allowed_signers
</code></pre>
<p>例如我的列表文件 allowed_signers</p>
<pre><code class="lang-bash">tobychung@duck.com ssh-ed25519 AAAA(...已省略)RuQj tobychung@duck.com
</code></pre>
<ul>
<li>指定可信公钥列表文件</li>
</ul>
<pre><code class="lang-bash">git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
</code></pre>
<ul>
<li>开启全局自动签名</li>
</ul>
<pre><code class="lang-bash">git config --global commit.gpgsign <span class="hljs-literal">true</span>
git config --global tag.gpgsign <span class="hljs-literal">true</span>
</code></pre>
<h2 id="heading-5rwl6kv546w5pyj5lut5bqt">测试现有仓库</h2>
<pre><code class="lang-bash">git commit --allow-empty --message=<span class="hljs-string">"Testing SSH signing"</span>
</code></pre>
<h2 id="heading-5pl55yl5625zcn">查看签名</h2>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span> --show-signature -3
</code></pre>
<p>这个时候我们就可以看到第一条有<code>Good "git" signatures ...</code>验证消息了。</p>
<h2 id="heading-github">GitHub 认证标识</h2>
<p>点击账号设置 SSH and GPG keys 中勾选 Vigilant mode![勾选认证]((2022-08-30) 使用 SSH 签名 Git 提交记录/勾选认证.png)</p>
<p>再次添加相同的公钥重点 <code>Key type</code> 要选择 <code>signing key</code> 即可。</p>
<pre><code class="lang-bash">clip &lt; ~/.ssh/id_ed25519.pub
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1663318561458/AKt-iZOfZ.png" alt="Testing SSH signing" /></p>
<h2 id="heading-5yc6icd">参考</h2>
<ul>
<li><a target="_blank" href="https://github.blog/changelog/2022-08-23-ssh-commit-verification-now-supported/">SSH commit verification now supported | GitHub Changelog</a></li>
<li><a target="_blank" href="https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification#ssh-commit-verification">About commit signature verification - GitHub Docs</a></li>
<li><a target="_blank" href="https://taoshu.in/git/ssh-sign.html">使用 SSH 签名 Git 提交记录</a></li>
<li><a target="_blank" href="https://calebhearth.com/sign-git-with-ssh">Signing Git Commits with Your SSH Key</a></li>
</ul>
]]></content:encoded></item></channel></rss>