<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Yarmo - gpg</title>
    <subtitle>Blog of an Open Source developer</subtitle>
    <link rel="self" type="application/atom+xml" href="https://yarmo.eu/tags/gpg/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://yarmo.eu"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2022-05-03T09:00:12+00:00</updated>
    <id>https://yarmo.eu/tags/gpg/atom.xml</id>
    <entry xml:lang="en">
        <title>GPG import public key from smartcard</title>
        <published>2022-05-03T09:00:12+00:00</published>
        <updated>2022-05-03T09:00:12+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://yarmo.eu/blog/gpg-import-from-smartcard/"/>
        <id>https://yarmo.eu/blog/gpg-import-from-smartcard/</id>
        
        <content type="html" xml:base="https://yarmo.eu/blog/gpg-import-from-smartcard/">&lt;h2 id=&quot;TLDR&quot;&gt;TLDR&lt;&#x2F;h2&gt;
&lt;p&gt;On a new computer, insert your USB OpenPGP smartcard and run:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#212733;color:#ccc9c2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;gpg&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffcc66;&quot;&gt; --card-edit
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;fetch
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;quit
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;Explanation&quot;&gt;Explanation&lt;&#x2F;h2&gt;
&lt;p&gt;I have a &lt;a href=&quot;https:&#x2F;&#x2F;www.yubico.com&#x2F;products&#x2F;yubikey-5-overview&#x2F;&quot;&gt;YubiKey 5&lt;&#x2F;a&gt; (still waiting on my &lt;a href=&quot;https:&#x2F;&#x2F;www.indiegogo.com&#x2F;projects&#x2F;solo-v2-safety-net-against-phishing#&#x2F;&quot;&gt;Solo v2&lt;&#x2F;a&gt;) on which I store my OpenPGP secret key.&lt;&#x2F;p&gt;
&lt;p&gt;However, if I boot into a new system, insert my USB OpenPGP smartcard, import my public key from a keyserver:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#212733;color:#ccc9c2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;gpg&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffcc66;&quot;&gt; --keyserver&lt;&#x2F;span&gt;&lt;span&gt; hkps:&#x2F;&#x2F;keys.openpgp.org&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffcc66;&quot;&gt; --recv-keys&lt;&#x2F;span&gt;&lt;span&gt; ABCD1234
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Tools-Signing-Your-Work&quot;&gt;configure git&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#212733;color:#ccc9c2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffcc66;&quot;&gt; --global&lt;&#x2F;span&gt;&lt;span&gt; user.signingkey ABCD1234
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and attempt to sign a commit, I&#x27;ll get an error message:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#212733;color:#ccc9c2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;git&lt;&#x2F;span&gt;&lt;span&gt; commit&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffcc66;&quot;&gt; -S -m &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bae67e;&quot;&gt;&amp;quot;Signed commit&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#5c6773;&quot;&gt;# error: gpg failed to sign the data
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#5c6773;&quot;&gt;# fatal: failed to write commit object
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;GPG doesn&#x27;t know yet it can interact with the private key stored on the USB OpenPGP smartcard!&lt;&#x2F;p&gt;
&lt;p&gt;So, instead of importing the public key from a keyserver, fetch it from the smartcard with the following commands:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#212733;color:#ccc9c2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;gpg&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffcc66;&quot;&gt; --card-edit
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;fetch
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffd580;&quot;&gt;quit
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
</feed>
