<?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>Sun, 30 Aug 2026 05:33:45 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>linux</category><category>security</category>
		<content:encoded><![CDATA[<h3>Password Management</h3><p>I&#x27;ll start this post by saying one thing. Are you SURE you want to wipe that</p><p>yubikey? I spent the last 2 weeks redoing my entire password manager. Silly me</p><p>forgot that I had my passwords encrypted using the yubikey I wiped to create</p><p>new PGP keys.</p><p>Anyways over the past week or two I moved all my passwords from</p><p><a href="https://www.passwordstore.org/">pass</a> into <a href="https://keepass.info/">keepass</a></p><p>and then back into pass when keepass didn&#x27;t meet all my needs for a password</p><p>manager. KeePass supported using yubikeys for decryption, but not more than one</p><p>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 [Yubikey 5C</p><p>NFC](https://www.yubico.com/ca/product/yubikey-5c-nfc/) to go alongside my</p><p>previous <a href="https://www.yubico.com/ca/product/yubikey-5c/">Yubikey 5C</a>. There</p><p>might be better alternatives, but this is the one I purchased. This one had NFC</p><p>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</p><p>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&#x27;re</p><p>generating on the device. I used RSA 4096 for my Yubikey 5C and ed25519 for the</p><p>Yubikey 5C NFC. I can&#x27;t use RSA or larger keys if I want to be able to use it</p><p>with NFC.</p><p>I backed up my revokal certificates that were put in the <code>~/.gnupg/</code> directory</p><p>as indicated after they were generated, and I exported and backed up the public</p><p>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 `pass init 0F6D5021A87F92BA</p><p>F9BC985B3BF972C7`. That lets me encrypt to both Yubikeys at once. Now if I lose</p><p>or accidentally wipe one of the Yubikeys again the other will be able to</p><p>decrypt my passwords. I also signed the keys with each other, just to show that</p><p>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</p><p>Yubikeys on every account that supported it. Google actually has something</p><p>cool called Advanced Protection which allows you to set up your account with 2</p><p>yubikeys to login with, so I enabled that for my Google account.</p><p>I downloaded the [password</p><p>store](https://play.google.com/store/apps/details?id=dev.msfjarvis.aps) Android</p><p>app for my phone, along with <a href="https://www.openkeychain.org/">Openkeychain</a>.</p><p>This part wasn&#x27;t too hard to set up, I just searched for my key on the</p><p>keyserver that I just uploaded it to, then imported it. I went through the</p><p>setup to add a security token and imported it so that it was recognized as one</p><p>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</p><p>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</p><p>named <code>git</code> and added my ssh keys to it, then inside it&#x27;s home directory I made</p><p>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</p><p>authentication from my phone. On my laptop I set up gpg-agent with ssh support</p><p>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</p><p>the server.</p><p>I used pass for 2FA as well because the password store app supports that. I</p><p>just scanned the code and installed <code>pass-otp</code> on Fedora to get support for</p><p>OTPs.</p><p>I installed the <a href="https://github.com/passff/passff">PassFF</a> Firefox extention to</p><p>get support for pass in my browser, and turned on autofill on my phone so that</p><p>it can autofill everywhere.</p><p>I set up git to sign all my commits so that it shows that my commits are signed</p><p>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</p><p>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</p><p>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</p><p><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</p><p>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</p><p>GDM for some reason, but I haven&#x27;t fixed it) require you to tap the yubikey</p><p>before typing the password. Two factors of authentication for my computer, and</p><p>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</p><p>git so that I could easily set the same thing up on my desktop which is also</p><p>running Fedora.</p>]]></content:encoded>
	</item>
	</channel>
</rss>