<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<atom:link href="https://seanbehan.ca/posts/tag/security/rss.xml" rel="self" type="application/rss+xml" />
		<title>Sean Behan — security</title>
		<link>https://seanbehan.ca/posts/tag/security</link>
		<description>Posts tagged “security”.</description>
		<language>en-CA</language>
		<!-- RSS wants an address here and readers show the name beside it. -->
		<managingEditor>sean@seanbehan.ca (Sean Behan)</managingEditor>
		<webMaster>sean@seanbehan.ca (Sean Behan)</webMaster>
		<lastBuildDate>Mon, 24 Aug 2026 08:56:20 GMT</lastBuildDate>
		<item>
		<guid isPermaLink="true">https://seanbehan.ca/posts/2fa-everything</guid>
		<title><![CDATA[2FA Everything]]></title>
		<description><![CDATA[Moving a password store between pass and KeePass, and getting two YubiKeys to guard all of it.]]></description>
		<link>https://seanbehan.ca/posts/2fa-everything</link>
		<pubDate>Fri, 04 Dec 2020 01:38:10 GMT</pubDate>
		<category>security</category><category>linux</category>
		<content:encoded><![CDATA[<!--[--><h3>Password Management</h3> <p>I’ll start this post by saying one thing. Are you SURE you want to wipe that
yubikey? I spent the last 2 weeks redoing my entire password manager. Silly me
forgot that I had my passwords encrypted using the yubikey I wiped to create
new PGP keys.</p> <p>Anyways over the past week or two I moved all my passwords from <a href="https://www.passwordstore.org/" rel="nofollow noopener noreferrer" target="_blank">pass</a> into <a href="https://keepass.info/" rel="nofollow noopener noreferrer" target="_blank">keepass</a> and then back into pass when keepass didn’t meet all my needs for a password
manager. KeePass supported using yubikeys for decryption, but not more than one
at a time. If I were to lose the key I would get permanently locked out.</p> <p>Features I want in my password manager:</p> <ul><li>2FA for password manager decryption</li> <li>Mobile and desktop apps</li> <li>Secure encryption</li></ul> <p>What I settled on was this. I bought myself a <a href="https://www.yubico.com/ca/product/yubikey-5c-nfc/" rel="nofollow noopener noreferrer" target="_blank">Yubikey 5C
NFC</a> to go alongside my
previous <a href="https://www.yubico.com/ca/product/yubikey-5c/" rel="nofollow noopener noreferrer" target="_blank">Yubikey 5C</a>. There
might be better alternatives, but this is the one I purchased. This one had NFC
and was convenient for accessing passwords on my phone and laptop.</p> <h3>Yubikey PGP Key Generation</h3> <p>To generate my PGP keys I actually generated them on the Yubikey itself, this
way the private key never touches the laptop I used to generate the key.</p> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>$ gpg --card-edit</span></span>
<span class="line"><span>gpg/card> admin</span></span>
<span class="line"><span>gpg/card> key-attr</span></span>
<span class="line"><span>gpg/card> generate</span></span></code></pre><!----> <p>The <code>key-attr</code> command lets you choose the type and size of key you’re
generating on the device. I used RSA 4096 for my Yubikey 5C and ed25519 for the
Yubikey 5C NFC. I can’t use RSA or larger keys if I want to be able to use it
with NFC.</p> <p>I backed up my revokal certificates that were put in the <code>~/.gnupg/</code> directory
as indicated after they were generated, and I exported and backed up the public
keys, then I uploaded the keys to a keyserver.</p> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>gpg --export --armor 0F6D5021A87F92BA > 0F6D5021A87F92BA.asc</span></span>
<span class="line"><span>gpg --send-keys 0F6D5021A87F92BA</span></span>
<span class="line"><span></span></span>
<span class="line"><span>gpg --export --armor F9BC985B3BF972C7 > F9BC985B3BF972C7.asc</span></span>
<span class="line"><span>gpg --send-keys F9BC985B3BF972C7</span></span></code></pre><!----> <p>I started putting passwords into pass using <code>pass init 0F6D5021A87F92BA F9BC985B3BF972C7</code>. That lets me encrypt to both Yubikeys at once. Now if I lose
or accidentally wipe one of the Yubikeys again the other will be able to
decrypt my passwords. I also signed the keys with each other, just to show that
both are valid if one were to be lost.</p> <p>While I did all this I thought I might as well enable 2FA using both the
Yubikeys on every account that supported it. Google actually has something
cool called Advanced Protection which allows you to set up your account with 2
yubikeys to login with, so I enabled that for my Google account.</p> <p>I downloaded the <a href="https://play.google.com/store/apps/details?id=dev.msfjarvis.aps" rel="nofollow noopener noreferrer" target="_blank">password
store</a> Android
app for my phone, along with <a href="https://www.openkeychain.org/" rel="nofollow noopener noreferrer" target="_blank">Openkeychain</a>.
This part wasn’t too hard to set up, I just searched for my key on the
keyserver that I just uploaded it to, then imported it. I went through the
setup to add a security token and imported it so that it was recognized as one
of my keys.</p> <h3>Git and Password Store Sync</h3> <p>At this point I set up my password store with git to use for syncing. I set it
up on some mirrors just in case one went down, and I backed it up to Nextcloud.</p> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>git remote add all git@seanbehan.dev:pass</span></span>
<span class="line"><span>git remote set-url --add --push all git@seanbehan.dev:pass</span></span>
<span class="line"><span>git remote set-url --add --push all git@git.sr.ht:~codebam/pass</span></span>
<span class="line"><span>git remote set-url --add --push all git@git.maych.in:codebam/password-store</span></span>
<span class="line"><span>git push --set-upstream all master</span></span></code></pre><!----> <p>I actually set up git on my own server here too. To do this I added a new user
named <code>git</code> and added my ssh keys to it, then inside it’s home directory I made
git repositories to push to using.</p> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>mkdir pass</span></span>
<span class="line"><span>cd pass</span></span>
<span class="line"><span>git init --bare</span></span></code></pre><!----> <h3>Yubikey for SSH</h3> <p>I generated a new SSH key from within the password store app and used that for
authentication from my phone. On my laptop I set up gpg-agent with ssh support
so that I could use my yubikey as an SSH key as well as a PGP key.</p> <h3><code>~/.bashrc</code></h3> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> GPG_TTY</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">tty</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">)"</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> SSH_AUTH_SOCK</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"/run/user/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$UID</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">/gnupg/S.gpg-agent.ssh"</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">gpg-connect-agent</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> updatestartuptty</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> /bye</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> ></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> /dev/null</span></span></code></pre><!----> <h3><code>~/.gnupg/gpg.conf</code></h3> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">use-agent</span></span></code></pre><!----> <p>Then I used <code>ssh-add -L</code> to show my public SSH key for each yubikey to put on
the server.</p> <p>I used pass for 2FA as well because the password store app supports that. I
just scanned the code and installed <code>pass-otp</code> on Fedora to get support for
OTPs.</p> <p>I installed the <a href="https://github.com/passff/passff" rel="nofollow noopener noreferrer" target="_blank">PassFF</a> Firefox extention to
get support for pass in my browser, and turned on autofill on my phone so that
it can autofill everywhere.</p> <p>I set up git to sign all my commits so that it shows that my commits are signed
and valid.</p> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>git config --global user.signingkey 0F6D5021A87F92BA</span></span>
<span class="line"><span>git config --global commit.gpgsign true</span></span></code></pre><!----> <h3>System-level U2F Authentication</h3> <p>As an extra layer of security on Fedora I installed the <code>pam-u2f</code> package on
and generated U2F logins.</p> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>sudo pamu2fcfg -uroot >> /etc/u2f_mappings</span></span></code></pre><!----> <p>I ran it once for each key, then opened the file and edit it so it looked like
this.</p> <h3>Before</h3> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>root:key1root:key2</span></span></code></pre><!----> <h3>After</h3> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>root:key1:key2</span></span>
<span class="line"><span>codebam:key1:key2</span></span></code></pre><!----> <p>In <code>/etc/pam.d/system-auth</code> I added a line to the very top above all the other <code>auth</code>.</p> <!----><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>auth	    required              pam_u2f.so authfile=/etc/u2f_mappings</span></span></code></pre><!----> <p>I added the same line to <code>/etc/pam.d/su</code> as well so that my user and root
requires a yubikey to <code>su</code>.</p> <p>This makes it so that <code>sudo</code>, <code>su</code>, and logging in through a <code>getty</code> (not in
GDM for some reason, but I haven’t fixed it) require you to tap the yubikey
before typing the password. Two factors of authentication for my computer, and
every online service that supports it, backed by hardware.</p> <p>Once I was done all this I committed my changes to my dotfiles pushed them to
git so that I could easily set the same thing up on my desktop which is also
running Fedora.</p><!--]-->]]></content:encoded>
	</item>
	</channel>
</rss>