Using Smart Card Readers with Firefox on Ubuntu


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.
.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.
If you logged in and enabled Sync, open Firefox and login to the same account to restore your settings.
If you backed up manually, complete the restoration steps in the Mozilla documentation.
Load the OpenSC Module in Firefox
Open Firefox, and go to Settings.
Select Privacy & Security on the left sidebar.
Scroll down to Security > Certificates.
Click Security Devices...
Click Load.
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
Click OK. Firefox may freeze for several seconds. If it gives you a warning, select Wait.
Once the module loads, select the OK button on the Device Manager screen.
If you have not already, connect your smart card reader and insert your smart card or badge.
Close and reopen Firefox.
You can now login to applications that require your smart card or badge!
Subscribe to my newsletter
Read articles from Ethan Dean directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
