Running proprietary drivers, such as the NVIDIA Graphics Driver, on a Linux distribution with Secure Boot enabled is a procedure often complicated by specific toolchain failures. To replace a graphics card and install proprietary drivers, the system must sign the third-party modules to allow them to load. Your system may work fine with the default drivers that come with your distribution. However, on my system, my mouse left trails of white pixels on GitHub Desktop as I moved it around. After the fixes in this guide, the display is running perfectly. Also, the full capability of my GPU for Cuda tasks has been unlocked.
This comprehensive solution was developed and validated across multiple Ubuntu installations—from LTS versions to the latest release – proving its robustness against various kernel versions. We found that the standard signing process can fail due to a combination of three low-level bugs:
- The
sign-fileutility fails to handle password-protected private keys. - The signing scripts do not account for ZSTD compression of kernel modules (
.ko.zst). - The
mokutilimport utility demands a DER key format, which is not the default output of standard key generation commands.
This guide documents the necessary workarounds to bypass these failures, resulting in a fully signed and functional NVIDIA driver running securely on any current Ubuntu system.
I have made use of Gemini and other AI for solving the issues described here and for the initial draft of this post.
Preamble: Diagnosis and Prerequisites
Before diving into the complex manual fix, you must confirm that Secure Boot is enabled and attempt the simplest installation method first.
Check Secure Boot Status
This command verifies if your operating system recognizes Secure Boot as being active:
mokutil --sb-state
If this shows disabled, you must enable it in your UEFI/BIOS before proceeding with this guide. Alternatively, if you currently don’t have Secure Boot and don’t want or need it then the standard installation may be sufficient. If you have Secure Boot enabled and the NVidia graphics drivers have not loaded, this guide may help.
The Quick Test: Standard Installation
On modern Ubuntu releases (like 25.10 “Questing”), the standard DKMS toolchain may already be patched, allowing a simple installation to succeed.
- Hit the Start key and search for “Additional Drivers”.
- Select the recommended NVIDIA driver for your system and click Apply Changes.
- Reboot the system.
Check NVIDIA Driver Status
Now we can check if the operating system has loaded the drivers.
# Check if the kernel modules are loaded
lsmod | grep nvidia
# Check if the NVIDIA card is recognized and functional
nvidia-smi
If the drivers have load successfully, you can stop here!
Expected Output (if the problem exists): The lsmod command may show no nvidia modules, or nvidia-smi may fail with an error like NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver.
If both checks confirm Secure Boot is enabled and your NVIDIA drivers are failing, you are ready to begin the patching procedure.
Step 1: Key Generation and System Setup
Before tackling the bugs, we need a foundational element: a Machine Owner Key (MOK) pair. This pair consists of a private key (for signing modules) and a public certificate (for enrolling with UEFI/BIOS).
Prerequisites Check
Ensure you have the necessary tools and packages installed. The openssl utility and the kernel headers are essential for this process.
# Check if the openssl utility is available (it usually is)
openssl version
# Ensure the kernel headers and mokutil are installed
sudo apt update
sudo apt install build-essential linux-headers-$(uname -r) mokutil
Generating the MOK Key Pair
We will use openssl to generate a 2048-bit RSA key pair. You will be prompted to enter a strong passphrase. This passphrase protects your private key (MOK.priv) and is the source of all the frustration later on—we will need to temporarily disable it.
Important: Store your passphrase securely, as you will need it in the next steps.
If you already have a key pair at /etc/ssl/MOK.priv and /etc/ssl/MOK.pem you can skip this step.
# Create the MOK key pair, valid for 10 years (3650 days).
# We name the output MOK.pem as that is its actual content format.
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -out MOK.pem -days 3650 -subj "/CN=NVIDIA MOK Key/"
Moving Keys and Finalizing Setup
After generation, the keys are in your home directory. We will now move the keys to the secure, system-wide location (/etc/ssl/), ensure they have correct ownership, and then delete them from the home directory for security.
# Move the keys to /etc/ssl
sudo cp MOK.priv /etc/ssl/
sudo cp MOK.pem /etc/ssl/
# Ensure the private key has restrictive permissions (root owner, read-only)
sudo chown root:root /etc/ssl/MOK.priv
sudo chmod 400 /etc/ssl/MOK.priv
# DELETE THE KEYS FROM THE HOME DIRECTORY FOR SECURITY
rm MOK.priv MOK.pem
We now have the two critical files safely located:
/etc/ssl/MOK.priv: The Private Key (password protected).
/etc/ssl/MOK.pem: The Public Certificate (used for enrollment).
The Two-Part Problem: Signing and Format Errors
With the keys securely in /etc/ssl/, we encounter the reason this procedure requires manual intervention. If you were to try to install or sign a driver now (or if DKMS tries to do it automatically), the process would fail due to two independent, yet interconnected, bugs in the standard Linux toolchain:
Signing Failure (The Passphrase Bug)
The tool at the center of this failure is the sign-file script. This utility is distributed with the general Linux kernel headers (not just Ubuntu) and is responsible for adding cryptographic signatures to kernel modules. Therefore, this bug affects any Linux distribution relying on this toolchain.
The script is unable to correctly handle the passphrase protecting your MOK.priv file. When it tries to read the key, it crashes with a cryptic error related to OpenSSL’s file input:
- SSL error:FFFFFFFF80000002:system library::No such file or directory: ../crypto/bio/bss_file.c:67
This error is our primary obstacle. In the next step, we will design a secure workaround by temporarily unlocking the private key, thus preventing the sign-file script from crashing and allowing the modules to be signed.
I’ve reported this bug to the Ubuntu team at: Launchpad Bug #2119337
Enrollment Failure (The Format Conflict)
The mokutil utility, which we use later to enroll the key into the UEFI system, is extremely rigid. Even if we successfully sign the modules, mokutil demands that the public key be in the binary DER (Distinguished Encoding Rules) format.
Since our MOK.pem file is in the human-readable PEM format, mokutil will reject it, forcing us to perform an explicit conversion before the final enrollment.
The next major section will provide the multi-step solution to bypass the first problem: the signing failure caused by the protected private key and ZSTD compression.
The Core Fix – Signing the Modules
This is the multi-step process required to successfully sign the kernel modules, bypassing the limitations of the sign-file utility and the ZSTD compression of the kernel.
Workaround 1: Creating the Unlocked Private Key
To prevent the sign-file script from crashing due to its inability to handle the passphrase, we must temporarily create an unprotected copy of your private key (MOK.priv).Security Note: We create this unlocked key in /etc/ssl/ but you must delete it immediately after the signing process is complete.
# Back up the protected key (MOK.priv.bak)
sudo cp /etc/ssl/MOK.priv /etc/ssl/MOK.priv.bak
# Create the UNLOCKED key. You will be prompted for your MOK passphrase here.
sudo openssl rsa -in /etc/ssl/MOK.priv -out /etc/ssl/MOK_unlocked.priv
We now use /etc/ssl/MOK_unlocked.priv for signing.
Workaround 2: Handling ZSTD Compression and Signing
On modern Linux kernels (like 6.8.x), modules are compressed using ZSTD and named .ko.zst. The sign-file script only works on uncompressed files (.ko).We must find the target NVIDIA modules, loop through them, decompress them, sign them using our unlocked key, and then re-compress them.
Preparation: Identify the location of the NVIDIA modules installed by DKMS.
The correct directory can vary between Ubuntu releases. We must confirm the path where the proprietary kernel modules have been placed.
Diagnostic Check: Run this command to find the required files. The output line you want is the directory containing nvidia.ko.zst.
sudo find /lib/modules/$(uname -r) -name 'nvidia.ko.zst'
If the command above fails to return the proprietary module files, you may need to force a DKMS rebuild (e.g., sudo apt install --reinstall nvidia-driver-XXX).
Set the correct path based on the output above. (The most common path is shown below).
# Set a variable for the module directory (e.g., /lib/modules/6.8.0-xx-generic/updates/dkms)
NVIDIA_DIR="/lib/modules/$(uname -r)/updates/dkms"
# Check if the directory exists (optional verification step)
ls -al ${NVIDIA_DIR}
The Signing Loop:
Run this entire code block as a single operation. It finds all compressed NVIDIA modules, performs the necessary three-step transformation (decompress, sign, re-compress), and cleans up the temporary uncompressed files.
# This loop performs the full decompression, signing, and re-compression process
for MODULE_ZST in ${NVIDIA_DIR}/*.ko.zst; do
MODULE_KO=${MODULE_ZST%.zst}
echo "Processing: ${MODULE_ZST}"
# 1. Decompress the ZSTD module to create the target .ko file
sudo zstd -d "${MODULE_ZST}" -o "${MODULE_KO}"
# 2. Sign the uncompressed .ko file using the UNLOCKED private key
# MOK.pem contains the certificate corresponding to MOK_unlocked.priv
sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 \
/etc/ssl/MOK_unlocked.priv /etc/ssl/MOK.pem "${MODULE_KO}"
# 3. Re-compress the now-signed .ko file back to .ko.zst, overwriting the original
sudo zstd "${MODULE_KO}" -o "${MODULE_ZST}" --rm
done
Clean Up the Unlocked Key
Immediately after the loop completes successfully, you must delete the unprotected copy of your private key to restore security integrity.
# Remove the unprotected copy of the private key
sudo rm /etc/ssl/MOK_unlocked.priv
With the modules signed, we have successfully overcome the first major set of obstacles. The final step is key enrollment.
Step 3: Enrollment and Final Format Correction
The modules are now signed using your key. The final step is to instruct the UEFI system to trust your key by queuing the public certificate for enrollment. This step is complicated by the rigid input requirements of the mokutil utility.
The Final Conflict: PEM vs. DER
Your long-term certificate file (MOK.pem) is in the flexible, human-readable PEM (ASCII/Base64) format.The mokutil tool on your system specifically demands the public key input be in the DER (binary) format to successfully queue the key.If you attempt to import the key directly, it will fail:
Abort!!! /etc/ssl/MOK.pem is not a valid x509 certificate in DER format
The Necessary Conversion Workaround
We must use openssl again to convert the key to the binary DER format just for the enrollment command. We use a timestamp in the filename for easy identification of this temporary enrollment artifact.
# 1. Set a timestamp variable for the new, temporary filename
TS=$(date +%Y%m%d_%H%M)
# 2. Use openssl to read the PEM format (-inform PEM) and write the required DER format (-outform DER).
sudo openssl x509 -in /etc/ssl/MOK.pem -inform PEM -out /etc/ssl/MOK_$TS.der -outform DER
Queuing the Key for Enrollment
You can now use the properly formatted DER file to queue the key for enrollment
# Import the new, properly formatted DER file.
sudo mokutil --import /etc/ssl/MOK_$TS.der
STOP: This command will successfully execute and prompt you to set the One-Time Password. This is the password you will use in the next step when the system reboots. Store it securely!
System Reboot and UEFI Enrollment
Once the password is set, reboot the system to complete the enrollment process.
sudo reboot
- When the machine restarts, it will interrupt the boot sequence and show the MokManager blue screen.
- Select Enroll MOK.
- Select Continue and confirm the key fingerprint.
- You will be prompted to enter the One-Time Password you just created in the terminal.
- Once enrollment is complete, select Reboot.
After the system boots up, the final step is to verify that all modules are loading correctly.
Verification and Conclusion
After the successful reboot and MOK enrollment in the UEFI screen, your custom signing key is now trusted by the system. The final step is to verify that Secure Boot is active and that your signed NVIDIA modules are loading correctly.
Verification Checks
Run these commands to confirm success:
Confirm MOK Enrollment and Secure Boot Status
Check that the key has been successfully written to the database and that the operating system recognizes Secure Boot is active:
# Check if the public key is present in the database
mokutil --list-enrolled
# Confirm Secure Boot is active
mokutil --sb-state
- Expected Output:
mokutil --sb-stateshould return:SecureBoot enabled - Confirmation: The
mokutil --list-enrolledoutput should show yourCN=NVIDIA MOK Keycertificate fingerprint.
Confirm NVIDIA Driver is Loading
If the verification steps above are successful, the signed kernel modules will now be allowed to load.
# Check if the kernel modules are loaded
lsmod | grep nvidia
# Check if the NVIDIA card is recognized and fully functional
nvidia-smi
- Expected Output: Both commands must succeed.
lsmodshould list allnvidiamodules (e.g.,nvidia_drm,nvidia_uvm), andnvidia-smishould display the driver version and GPU status without error.
You should now clean up any DER certificates that you created for the MOK enrollment. They are based on the public PEM key and are no more secret than that file. However, it’s better practice to have one source of truth.
sudo rm /etc/ssl/MOK_*.der
Conclusion
The complex procedure of installing NVIDIA drivers under Secure Boot is now complete. You have successfully navigated and engineered workarounds for the three core defects in the Linux signing toolchain: the sign-file passphrase bug, the ZSTD compression conflict, and the mokutil format rigidity.
This solution was developed on an active test system and is confirmed to work across multiple environments, including LTS and latest release Ubuntu systems, hopefully demonstrating a robust and universal fix for this problem.




