The ultimate guide to Yubikey on WSL2 [Part 4]

If you haven’t setup GPG on Yubikey or you cannot access Yubikey from within WSL. Please check Parts 1 and 2 of this series.

Disclaimer: This tutorial is wrote for WSL2 with Ubuntu. It may differ distro from distro.

Managing secrets in WSL with Yubikey

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

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:

There is actually a better way to approach this. Unix systems provides pass as a standard secrets manager and WSL is no exception.

Pass stores your secrets in files which are encrypted by your GPG key.

Since we have already set up our GPG key with Yubikey. We can use it to encrypt and decrypt our secrets in pass.

Initializing pass store

For this we will need ID of our GPG key. You can get it via

Getting GPG ID

Copy this key over and init the pass storage via

Adding secrets to pass

Let’s take a look at example using mysql password. Let’s create a secret named mysql-pass

Now paste the password two times and that’s it.

Getting the secret value

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

Assuming you have connected your Yubikey, you can get the value via

It’ll promt you to enter your PIN.

PIN Prompt

After unlocking your card, pass will print you the secret.

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

Other useful commands

Here I’m listing just a bunch of other commands which I found useful.

What can be usefull for teams is an ability to share the encrypted pass files over GIT using

More info can be found here.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store