Using Smart Card Readers with Firefox on Ubuntu

Ethan DeanEthan Dean
4 min read

The following article guides you through the process of having Firefox recognize and use a smart card or badge reader on Ubuntu. These steps are specifically for Firefox on Ubuntu. You may have success with other browsers by following similar steps, but this is not guaranteed.

The following instructions were tested and verified to work on Ubuntu 22 and 24.

What's Causing Issues?

Using smart card or badge readers on Ubuntu is not as simple as plugging in the reader. The most likely cause for issues is Ubuntu's default Firefox version being a Snap package.

Snap packages WILL NOT WORK with a smart card or badge reader as APP ARMOR policies prevent this somewhere in the pipeline.

Regardless of which browser you try these steps with, avoid the Snap version of the browser in favor of .deb or apt package versions.

Step-By-Step Guide

The following steps will go through the process of backing up your browser settings, replacing your current browser, and setting up the new installation to use your smart card reader. Follow each of the steps carefully to fix the card reader issues.

Install Required Packages

Install the tools required for using your smart card reader:

sudo apt update && sudo apt install -y opensc

Connect your smart card reader if you have not done so already.

Check Firefox Installation Type

First, check if the version of Firefox you're using is a Snap package:

snap list | grep firefox
  • If nothing is returned, you should be okay to skip to the Load the OpenSC Module section below.

  • If you see Firefox listed, continue reading the steps below.

Backup Firefox Settings

The next section will have you delete your current browser installation. Any unsaved settings will be lost forever!

The easiest way, and therefore recommended way, to back up your settings is by logging into Firefox and turning on Firefox Sync. Alternatively, you can back up your settings manually by following the steps in the Mozilla documentation, though this is more complicated.

Remove Snap Firefox

After ensuring you have backed up your settings, remove Firefox completely:

sudo snap remove firefox && sudo apt purge -y firefox

Install .deb Firefox Package

To be able to use our smart card reader with Firefox on Ubuntu, we will replace the removed Snap version of Firefox with the .deb package version.

Follow the steps in the Install Firefox .deb Package for Debian-Based Distributions section of the Mozilla documentation.

The following code snippet should be similar to the commands you must run. Do not run the code below directly! This should only be used as reference as the latest commands may be different than what is shown below.

sudo install -d -m 0755 /etc/apt/keyrings

sudo apt install -y wget && wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null

gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}'
echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | sudo tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null

echo '
Package: *
Pin: origin packages.mozilla.org
Pin-Priority: 1000
' | sudo tee /etc/apt/preferences.d/mozilla 

sudo apt-get update && sudo apt-get install -y firefox

Restore Firefox Settings

If you backed up your Firefox data, you can go ahead and restore your configuration.

Load the OpenSC Module in Firefox

  1. Open Firefox, and go to Settings.

  2. Select Privacy & Security on the left sidebar.

  3. Scroll down to Security > Certificates.

  4. Click Security Devices...

  5. Click Load.

  6. Enter a name ('OpenSC' will do) and enter the path to the module:

    • On Ubuntu, this is usually located at: /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so

    • You can find it using the following command:

        find /usr/lib -name opensc-pkcs11.so
      
  7. Click OK. Firefox may freeze for several seconds. If it gives you a warning, select Wait.

  8. Once the module loads, select the OK button on the Device Manager screen.

  9. If you have not already, connect your smart card reader and insert your smart card or badge.

  10. Close and reopen Firefox.

You can now login to applications that require your smart card or badge!

0
Subscribe to my newsletter

Read articles from Ethan Dean directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ethan Dean
Ethan Dean