<?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: Jaroslav Živný</title>
    <description>The latest articles on DEV Community by Jaroslav Živný (@dzerycz).</description>
    <link>https://dev.to/dzerycz</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%2F224236%2Fd545f512-6e76-4a07-b231-0165afab877e.jpg</url>
      <title>DEV Community: Jaroslav Živný</title>
      <link>https://dev.to/dzerycz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dzerycz"/>
    <language>en</language>
    <item>
      <title>The ultimate guide to Yubikey on WSL2 [Part 4]</title>
      <dc:creator>Jaroslav Živný</dc:creator>
      <pubDate>Mon, 08 Mar 2021 15:23:19 +0000</pubDate>
      <link>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-4-69b</link>
      <guid>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-4-69b</guid>
      <description>&lt;p&gt;If you haven’t setup GPG on Yubikey or you cannot access YubiKey from within WSL. Please check previous parts (&lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed"&gt;1&lt;/a&gt;, &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli"&gt;2&lt;/a&gt;) of this series.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer I:&lt;/strong&gt; This tutorial is written for WSL2 with Ubuntu. It may differ distro from distro.&lt;/p&gt;




&lt;h1&gt;
  
  
  Managing secrets in WSL with Yubikey
&lt;/h1&gt;

&lt;p&gt;Everybody knows the pain with managing secrets. Let’s imagine, you want to access DB or curl an endpoint with base auth.&lt;/p&gt;

&lt;p&gt;Most of the people are copying the secrets from their own Secrets Managers (the real ones or plain text files) and placing them to the terminal or exporting them as an environment variable. Simply something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-u&lt;/span&gt; myusername http://example.com
password: &amp;lt;placing-password-here&amp;gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;mysql –umyusername –p
password: &amp;lt;placing-password-here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is actually a better way to approach this. Unix systems provides pass as a standard secrets manager and WSL is no exception.&lt;/p&gt;

&lt;p&gt;Pass stores your secrets in files which are encrypted by your GPG key.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In case &lt;code&gt;pass&lt;/code&gt; is not installed on your WSL distro, run: &lt;code&gt;sudo apt install pass&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed"&gt;Since we have already set up our GPG key with Yubikey&lt;/a&gt;. We can use it to encrypt and decrypt our secrets in pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initializing pass store
&lt;/h2&gt;

&lt;p&gt;For this we will need ID of our GPG key. You can get it via &lt;code&gt;gpg --list-keys&lt;/code&gt;&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%2Fpbbv49tnzo1w91uuqpnu.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%2Fpbbv49tnzo1w91uuqpnu.png" alt="Getting GPG ID"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy this key over and init the pass storage via&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pass init YOUR_KEY_ID &lt;span class="c"&gt;# In my case 1E9...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding secrets to pass
&lt;/h2&gt;

&lt;p&gt;Let’s take a look at example using mysql password. Let’s create a secret named mysql-pass&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pass add mysql-pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now paste the password two times and that’s it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting the secret value
&lt;/h2&gt;

&lt;p&gt;Perfect, you created your first secret. Now let’s take a look how to reveal the value and how to use it in commands.&lt;/p&gt;

&lt;p&gt;Assuming you have connected your Yubikey, you can get the value via&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pass mysql-pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’ll promt you to enter your PIN.&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%2Fom5jsun2g2s3ewgnjhax.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%2Fom5jsun2g2s3ewgnjhax.png" alt="PIN Prompt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After unlocking your card, pass will print you the secret.&lt;/p&gt;

&lt;p&gt;When you want to use the secret directly in the commands you can simply use subcommands. Let’s take a look at our mysql example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;mysql –umyusername –p&lt;span class="si"&gt;$(&lt;/span&gt;pass mysql-pass&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Other useful commands
&lt;/h2&gt;

&lt;p&gt;Here I’m listing just a bunch of other commands which I found useful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pass
&lt;span class="c"&gt;# Will show list of all secret names&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;pass &lt;span class="nb"&gt;rm&lt;/span&gt; &amp;lt;secret-name&amp;gt;
&lt;span class="c"&gt;# Will delete your secret&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;pass generate &amp;lt;secret-name&amp;gt;
&lt;span class="c"&gt;# Will generate a random secret for you and store it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What can be usefull for teams is an ability to share the encrypted pass files over GIT using &lt;code&gt;pass git ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;More info can be found &lt;a href="https://gist.github.com/abtrout/d64fb11ad6f9f49fa325" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>wsl</category>
      <category>pass</category>
      <category>secrets</category>
      <category>security</category>
    </item>
    <item>
      <title>The ultimate guide to Yubikey on WSL2 [Part 3]</title>
      <dc:creator>Jaroslav Živný</dc:creator>
      <pubDate>Tue, 16 Feb 2021 10:11:03 +0000</pubDate>
      <link>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-3-2d8d</link>
      <guid>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-3-2d8d</guid>
      <description>&lt;p&gt;If you haven’t setup GPG on Yubikey or you cannot access YubiKey from within WSL. Please check previous parts (&lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed"&gt;1&lt;/a&gt;, &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli"&gt;2&lt;/a&gt;) of this series.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer I:&lt;/strong&gt; This tutorial is written for WSL2 with Ubuntu. It may differ distro from distro.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer II:&lt;/strong&gt; I’m going to use Github in this tutorial, but process of setup for other major GIT servers (GitLab, Bitbucket, …) are pretty much the same.&lt;/p&gt;

&lt;p&gt;Let’s continue where we left off in &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli"&gt;part 2&lt;/a&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Authenticate against Git server via GPG
&lt;/h1&gt;

&lt;p&gt;In order to authenticate against GIT server we need a public ssh key. We connected WSL’s ssh agent in &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli"&gt;the 2nd part of this tutorial&lt;/a&gt; to GPG key over socket. So now we can use the public key from there.&lt;/p&gt;

&lt;p&gt;Get SSH public key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# WSL2&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;ssh-add &lt;span class="nt"&gt;-L&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take the output and paste it to &lt;em&gt;&lt;a href="https://github.com/settings/keys" rel="noopener noreferrer"&gt;GitHub settings -&amp;gt; SSH and GPG Keys&lt;/a&gt;&lt;/em&gt; -&amp;gt; &lt;strong&gt;New SSH Key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you now try to pull or push from remote GIT repository, there will show up a modal requesting your GPG PIN on your screen.&lt;/p&gt;




&lt;h1&gt;
  
  
  Signing git commits with GPG
&lt;/h1&gt;

&lt;h4&gt;
  
  
  1 - Configure Git by
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# WSL2&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.signingkey YOUR_KEY_ID &lt;span class="c"&gt;# In my case 1E9...&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; gpg.program gpg
git config &lt;span class="nt"&gt;--global&lt;/span&gt; commit.gpgsign &lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2 - Export Public Key
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# WSL2&lt;/span&gt;
gpg &lt;span class="nt"&gt;--armor&lt;/span&gt; &lt;span class="nt"&gt;--export&lt;/span&gt; YOUR_KEY_ID &lt;span class="c"&gt;# In my case 1E9...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3 - Put this public GPG key to &lt;em&gt;&lt;a href="https://github.com/settings/keys" rel="noopener noreferrer"&gt;GitHub Setting -&amp;gt; SSH and GPG keys&lt;/a&gt;&lt;/em&gt; -&amp;gt; &lt;strong&gt;New GPG Key&lt;/strong&gt;. In case you’re using GitLab, Bitbucket or other Git servers, there is a similar way to configure GPG Key.
&lt;/h4&gt;

&lt;p&gt;Now when you create a new commit, there will show up a dialog requesting your PIN on your screen.&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%2F3qvtn88l5za2whpjjntb.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%2F3qvtn88l5za2whpjjntb.PNG" alt="Dialog requesting your GPG PIN"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you’re using verified Email address (in Github) for the GPG key and you configured the same address in Git &lt;code&gt;git config --global user.email&lt;/code&gt;. You should be able to see Verified badge next to your commit.&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%2Fc99fr83j21j39iqqdjsu.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%2Fc99fr83j21j39iqqdjsu.png" alt="A Commit with Verified badge"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>wsl</category>
      <category>yubikey</category>
    </item>
    <item>
      <title>The ultimate guide to Yubikey on WSL2 [Part 2]</title>
      <dc:creator>Jaroslav Živný</dc:creator>
      <pubDate>Tue, 16 Feb 2021 10:10:35 +0000</pubDate>
      <link>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli</link>
      <guid>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli</guid>
      <description>&lt;p&gt;In the Previous part we &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed"&gt;configured OpenGPG with Yubikey&lt;/a&gt;. In case you have it done, we can continue on how to access your YubiKey in WSL2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; This tutorial is written for WSL2 with Ubuntu. It may differ distro from distro.&lt;/p&gt;




&lt;h1&gt;
  
  
  Access your YubiKey in WSL2
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Install socat and &lt;a href="https://github.com/BlackReloaded/wsl2-ssh-pageant" rel="noopener noreferrer"&gt;wsl2-ssh-pageant&lt;/a&gt; in WSL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# WSL2&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;socat scdaemon
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/.ssh
&lt;span class="nv"&gt;$ &lt;/span&gt;wget https://github.com/BlackReloaded/wsl2-ssh-pageant/releases/download/v1.4.0/wsl2-ssh-pageant.exe &lt;span class="nt"&gt;-O&lt;/span&gt; ~/.ssh/wsl2-ssh-pageant.exe
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x ~/.ssh/wsl2-ssh-pageant.exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sync sockets
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This part is inspired by &lt;a href="https://d3vffli1wot2ak.cloudfront.net/yubikey-wsl2.html" rel="noopener noreferrer"&gt;this tutorial&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Edit your &lt;code&gt;~/.bashrc&lt;/code&gt; or &lt;code&gt;~/.zshrc&lt;/code&gt; - depends on your shell (e.g. via nano or vim) and add following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config_path="C\:/Users/&amp;lt;YOUR_USER&amp;gt;/AppData/Local/gnupg"
wsl2_ssh_pageant_bin="$HOME/.ssh/wsl2-ssh-pageant.exe"
# SSH Socket
# Removing Linux SSH socket and replacing it by link to wsl2-ssh-pageant socket
export SSH_AUTH_SOCK="$HOME/.ssh/agent.sock"
if ! ss -a | grep -q "$SSH_AUTH_SOCK"; then
  rm -f "$SSH_AUTH_SOCK"
  if test -x "$wsl2_ssh_pageant_bin"; then
    (setsid nohup socat UNIX-LISTEN:"$SSH_AUTH_SOCK,fork" EXEC:"$wsl2_ssh_pageant_bin" &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;)
  else
    echo &amp;gt;&amp;amp;2 "WARNING: $wsl2_ssh_pageant_bin is not executable."
  fi
fi
# GPG Socket
# Removing Linux GPG Agent socket and replacing it by link to wsl2-ssh-pageant GPG socket
export GPG_AGENT_SOCK="$HOME/.gnupg/S.gpg-agent"
if ! ss -a | grep -q "$GPG_AGENT_SOCK"; then
  rm -rf "$GPG_AGENT_SOCK"
  if test -x "$wsl2_ssh_pageant_bin"; then
    (setsid nohup socat UNIX-LISTEN:"$GPG_AGENT_SOCK,fork" EXEC:"$wsl2_ssh_pageant_bin --gpgConfigBasepath ${config_path} --gpg S.gpg-agent" &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;)
  else
    echo &amp;gt;&amp;amp;2 "WARNING: $wsl2_ssh_pageant_bin is not executable."
  fi
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart WSL by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# CMD
wsl.exe --shutdown
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you open Ubuntu Terminal now and run &lt;code&gt;gpg --card-status&lt;/code&gt; you should be able to see something like this:&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%2Fted0rz5yf5b89n30ohcd.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%2Fted0rz5yf5b89n30ohcd.PNG" alt="gpg --card-status"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Import GPG key to WSL2
&lt;/h3&gt;

&lt;p&gt;If you check GPG keys availible in WSL2 via &lt;code&gt;gpg --list-keys&lt;/code&gt; or &lt;code&gt;gpg --list-secret-keys&lt;/code&gt; you get empty results. We have to first import them. It’s quite easy just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# WSL2&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;gpg &lt;span class="nt"&gt;--card-edit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open gpg command interface. Just type in &lt;code&gt;fetch&lt;/code&gt;. It’ll get you public keys from &lt;a href="https://keys.openpgp.org/" rel="noopener noreferrer"&gt;keys.openpgp.org&lt;/a&gt; (we uploaded them there in &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed"&gt;the previous part&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In case you haven’t uploaded the public keys to &lt;a href="https://keys.openpgp.org/" rel="noopener noreferrer"&gt;keys.openpgp.org&lt;/a&gt; (as shown in the &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed"&gt;part 1&lt;/a&gt; of this tutorial). You can import it via asc file (exported in &lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed"&gt;part 1&lt;/a&gt;) via:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gpg --import PATH_TO_ASC_FILE&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Exit the gpg command interface via &lt;code&gt;quit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you now run &lt;code&gt;gpg --list-keys&lt;/code&gt; you finally get your keys.&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%2Ff5gim80dtf53xy55gt2w.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%2Ff5gim80dtf53xy55gt2w.png" alt="gpg --list-keys"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Great success!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we are missing one small step. As you can see. The trustworthiness of our certificate is unknown (information next to the name). We can change it via running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# WSL2&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;gpg &lt;span class="nt"&gt;--edit-key&lt;/span&gt; YOUR_KEY_ID &lt;span class="c"&gt;# In my case 1E9...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This opens gpg console insterface. Write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# WSL2&lt;/span&gt;
trust &lt;span class="c"&gt;# Change trust level&lt;/span&gt;
5     &lt;span class="c"&gt;# Set trust level to ultimate&lt;/span&gt;
save  &lt;span class="c"&gt;# Save the changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you list keys via &lt;code&gt;gpg --list-keys&lt;/code&gt; now. You should be able to see &lt;code&gt;[ultimate]&lt;/code&gt; next to your name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Tips
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Yubikey stopped working on WSL
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Unplug Yubikey&lt;/li&gt;
&lt;li&gt;Shutdown wsl &lt;code&gt;wsl --shutdown&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Shutdown Kleopatra in Task manager&lt;/li&gt;
&lt;li&gt;Shutdown wsl2-ssh-pageant in Task manager&lt;/li&gt;
&lt;li&gt;Start Kleopatra&lt;/li&gt;
&lt;li&gt;Start wsl - open a new window&lt;/li&gt;
&lt;li&gt;Plug in the Yubikey&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Getting "error: Couldn't load public key XXX No such file or directory?"
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/73726815/git-commit-failed-couldnt-load-public-key" rel="noopener noreferrer"&gt;Unset gpg.format via &lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli"&gt;We’ll continue in the part 3.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>yubikey</category>
      <category>wsl</category>
      <category>windows10</category>
      <category>gpg</category>
    </item>
    <item>
      <title>The ultimate guide to Yubikey on WSL2 [Part 1]</title>
      <dc:creator>Jaroslav Živný</dc:creator>
      <pubDate>Tue, 16 Feb 2021 10:08:51 +0000</pubDate>
      <link>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed</link>
      <guid>https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-1-5aed</guid>
      <description>&lt;p&gt;There are already a few tutorials on the Internet with topic "how to make Yubikey work on WSL". But when I followed them I had to do a lot of troubleshooting anyway. Therefore I decided to write down a complete guide to the setup (up to date in 2021).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We are going to go through a couple of use cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setup OpenGPG with Yubikey&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli"&gt;Access your YubiKey in WSL2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-3-2d8d"&gt;Authenticate against Git server via GPG &amp;amp; Signing git commits with GPG&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Other parts will be added in the future&lt;/em&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Setup of Yubikey and connect it with WSL2
&lt;/h1&gt;

&lt;p&gt;In this part we are going to take a look on how to get Yubikey connected to WSL2. Because WSL does not have access to USB devices, we have to make it connect to our Windows host and then forward the connection to WSL.&lt;/p&gt;

&lt;p&gt;First, we are going to need a YubiKey that supports OpenPGP (Security Key Series or YubiKey FIPS Series are not sufficient)&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;To make our Smart key work with windows we are going to need GnuPG and Putty. You can either download it here:&lt;br&gt;
&lt;a href="https://gpg4win.org/index.html" rel="noopener noreferrer"&gt;GnuPG install it with Kleopatra&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.putty.org/" rel="noopener noreferrer"&gt;Putty&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;or get it via chocolate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# CMD
choco install gnupg putty.install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure GnuPG
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# CMD
mkdir %HOMEPATH%\AppData\Roaming\gnupg
echo enable-putty-support◙enable-ssh-support &amp;gt; %HOMEPATH%\AppData\Roaming\gnupg\gpg-agent.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can connect your Yubikey now. Open Kleopatra (you have to open it from system tray) and go to Smartcards.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you don't see your Yubikey go to &lt;em&gt;Settings -&amp;gt; Configure Kleopatra -&amp;gt; GnuPG System -&amp;gt; Smartcards&lt;/em&gt; and set Connect to reader at port N to Yubico YubiKey OTP+FIDO+CCID 0. Save it, reconnect Yubikey and restart Kleopatra. Now you should be able to see it.&lt;br&gt;
You can also verify it in CMD via: &lt;code&gt;gpg --card-status&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&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%2F946kfcaptejudj5mzbme.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%2F946kfcaptejudj5mzbme.PNG" alt="A Brand new or Wiped out Yubi key should show up like this"&gt;&lt;/a&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%2Fj9rjljlm536yhcywp6b3.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%2Fj9rjljlm536yhcywp6b3.png" alt="Outout of gpg - cart-status"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up a new YubiKey
&lt;/h3&gt;

&lt;p&gt;In case you already have an OpenPGP key on your YubiKey, please skip this part and go directly to &lt;strong&gt;part 2&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I personaly found generating the keys in Kleipatra GUI the most straightforward. Although it doesn't give you that many configuration possibilities.&lt;/p&gt;

&lt;p&gt;If you're setting up Your Yubikey for the first time, don't forgot to change your PIN and Admin PIN. Both operations can be done in Kleopatra -&amp;gt; Smartcards -&amp;gt; Change PIN and Change Admin PIN. Default PINs can be found &lt;a href="https://developers.yubico.com/PIV/Introduction/YubiKey_and_PIV.html#:~:text=Technical%20details%20about%20the%20YubiKey,default%20PUK%20code%20is%2012345678." rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1 - Generate GPG keys
&lt;/h4&gt;

&lt;p&gt;In Kleopatra -&amp;gt; Smartcards click at Generate New Keys. A dialog will pop up. Enter your name, email and as algorithm choose the highest available.&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%2Fn0y2kgp33pucmhq5md5r.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%2Fn0y2kgp33pucmhq5md5r.png" alt="Generating Your GPG Keys"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now enter your PIN, then your Admin PIN (pay attention to what the modal window wants) - it's going to need your PIN several times. In case you encounter with an issue, &lt;a href="https://support.yubico.com/hc/en-us/articles/360013761339-Resetting-the-OpenPGP-Applet-on-the-YubiKey" rel="noopener noreferrer"&gt;you can always reset your YubiKey&lt;/a&gt;. At the end enter password for the GPG key.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In case you're more comfortable with terminal interface, &lt;a href="https://support.yubico.com/hc/en-us/articles/360013790259-Using-Your-YubiKey-with-OpenPGP" rel="noopener noreferrer"&gt;please use this official tutorial&lt;/a&gt;. Just make sure, you are generating keys and/or subkeys for &lt;strong&gt;Signing, Encryption and Authorization.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now you should be able to see your keys.&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%2Fwy3hc8odowoh8o7qy6wm.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%2Fwy3hc8odowoh8o7qy6wm.png" alt="Generated Keys"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2 - Export your public key
&lt;/h4&gt;

&lt;p&gt;In Kleopatra go to Cartificates -&amp;gt; Right click at your newly created certificate and choose Export. This will save your public key to an &lt;em&gt;asc&lt;/em&gt; file&lt;/p&gt;

&lt;h4&gt;
  
  
  3 - Publish your public key
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;This step is not necessary, but I found it helpful when using GPG key in real life.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to &lt;a href="https://keys.openpgp.org/upload" rel="noopener noreferrer"&gt;keys.openpgp.org&lt;/a&gt;, choose your public key and click Upload.&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%2Feqdcpuukqk4r3wt84jqi.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%2Feqdcpuukqk4r3wt84jqi.png" alt="Uploading Public key to keys.openpgp.org"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click Send Verification Email, check your e-mail Inbox (or Spam) folder and click the verification link.&lt;/p&gt;

&lt;p&gt;To get link to your published Public key go to &lt;a href="https://keys.openpgp.org/" rel="noopener noreferrer"&gt;keys.openpgp.org&lt;/a&gt;, search for your email and copy the URL it shows.&lt;/p&gt;

&lt;p&gt;YubiKey has a nice handy space for storing this URL. Go to &lt;em&gt;Kleopatra -&amp;gt; Smartkeys -&amp;gt; Publickey URL&lt;/em&gt; and edit it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In case you don't see your keys or card in WSL after restart of your PC. Please start Kleopatra first and then restart wsl via wsl - shutdown&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Additional Tips
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Autostart Kleopatra on Windows Logon
&lt;/h4&gt;

&lt;p&gt;The easiest way to achieve it is via "Task Schduler"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Action -&amp;gt; Create a Basic Task&lt;/li&gt;
&lt;li&gt;Trigger: "When I log on"&lt;/li&gt;
&lt;li&gt;Action: Start a program&lt;/li&gt;
&lt;li&gt;Program/Script: Path to kleopatra.exe (should be &lt;code&gt;"C:\Program Files (x86)\Gpg4win\bin\kleopatra.exe"&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Import Yubikey to a new machine
&lt;/h4&gt;

&lt;p&gt;When you insert your Yubikey it should be visible in "Smartcards" section. If you don't see it follow &lt;code&gt;Configure GnuPG&lt;/code&gt; section.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the Publickey URL - this will download your public key&lt;/li&gt;
&lt;li&gt;Click Import in kleopatra menu and point to the downloaded file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that you should be able to continue to part 2 of this tutorial&lt;/p&gt;




&lt;p&gt;&lt;a href="https://dev.to/dzerycz/the-ultimate-guide-to-yubikey-on-wsl2-part-2-kli"&gt;We'll continue in the part 2.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>yubikey</category>
      <category>wsl</category>
      <category>git</category>
      <category>gpg</category>
    </item>
  </channel>
</rss>
