How to Install PFX Certificate via Command Line

Abstract: Install PFX certificates on Windows via PowerShell or convert them to PEM for Linux and macOS trust stores.

Created: 2026-07-30 by

Install a PFX certificate via command line by using Import-PfxCertificate on Windows, or by splitting the file into PEM format for Linux and macOS. On Unix-like systems, you must extract the private key and certificate separately before importing them into the system trust store to ensure both identity and encryption capabilities are properly configured.

Understanding PFX Files and Command Line Requirements

A Personal Information Exchange (PFX) file is a binary container that bundles an SSL/TLS certificate along with its associated private key and any intermediate certificates. This format is widely used for backing up and transferring certificate data between servers. When working from a command line interface, you cannot simply "drop" this file into a trust store because most operating systems require the private key and the public certificate to be handled distinctly for security reasons. The method of installation varies significantly depending on your operating system. Windows provides native PowerShell cmdlets that handle the binary parsing automatically. In contrast, Linux distributions and macOS rely on OpenSSL utilities or specific system security tools that expect Privacy-Enhanced Mail (PEM) encoded text files. Therefore, the first step for non-Windows environments is almost always converting the binary PFX structure into readable PEM components.

Windows Installation Using PowerShell

Windows offers the most straightforward path for administrators due to the built-in Import-PfxCertificate cmdlet available in PowerShell 3.0 and later. This command allows you to specify the file path, the password protecting the private key, and the target store location. To install a PFX certificate into the current user's personal store, open PowerShell as an administrator and run the following command:
Import-PfxCertificate -FilePath "C:\certs\mycertificate.pfx" -CertStoreLocation Cert:\CurrentUser\My -Password (ConvertTo-SecureString -String "YourPassword" -AsPlainText -Force)
If you need to install the certificate for all users on the machine, change the store location to Cert:\LocalMachine\My. You will also need to run the script with elevated privileges. The -Exportable flag can be added if you need to allow the private key to be exported later, though this is generally discouraged for high-security environments. Always verify the installation by checking the Certificate Manager console or running Get-ChildItem Cert:\CurrentUser\My.

Preparing PFX Files for Linux and macOS

On Linux and macOS, the native trust stores do not natively accept binary PFX files directly via simple import commands. Instead, you must use OpenSSL to split the PFX file into two separate PEM files: one containing the private key and another containing the certificate chain. This process ensures that the private key remains secure and distinct from the public certificate data. First, extract the private key from the PFX file. This command prompts you for the PFX password and then asks you to set a new password for the decrypted key file. For production use, it is recommended to remove the passphrase from the key file after extraction, but this makes the key less secure against unauthorized access if the file is stolen.
openssl pkcs12 -in certificate.pfx -nocerts -out key.pem -nodes
Next, extract the certificate portion. This creates a file containing the certificate and any intermediate CA certificates in PEM format.
openssl pkcs12 -in certificate.pfx -clcerts -nokeys -out cert.pem
You now have two files: key.pem for the private key and cert.pem for the certificate. These files are ready for platform-specific installation steps.

Installing on Linux Systems

Linux distributions typically manage certificates through the /etc/ssl/certs directory or via update-alternatives scripts like update-ca-certificates. However, for application-specific identities, such as web servers or API clients, the placement depends on the software configuration. For system-wide trust, copy cert.pem to /usr/local/share/ca-certificates/ and run sudo update-ca-certificates. If you are configuring a service like Nginx or Apache, point the configuration directives to the cert.pem and key.pem files created earlier. Ensure file permissions are strict; the private key should be readable only by root or the specific service user (chmod 600 key.pem).

Installing on macOS Systems

macOS uses the security command-line tool to manage the Keychain. A common misconception is that security add-certificate imports the private key. It does not. This command only adds the public certificate to the login keychain. To fully utilize a PFX-derived identity, you must perform two distinct steps. First, add the private key to the keychain. This command imports the decrypted PEM key and associates it with the login keychain.
security import key.pem -k ~/Library/Keychains/login.keychain-db -T /usr/bin/security
Second, add the certificate itself.
security import cert.pem -k ~/Library/Keychains/login.keychain-db -T /usr/bin/security
After importing, you may need to manually link the key and certificate in the Keychain Access app if they do not auto-match, ensuring the private key is marked as "Always Trust."

Troubleshooting Common Issues

When installing certificates via command line, permission errors are the most frequent obstacle. Ensure you are running with sufficient privileges, such as sudo on Linux/macOS or Administrator mode on Windows. Another common issue is password handling. If your PFX password contains special characters, you may need to escape them or use a variable to pass the string securely. Additionally, verify that the certificate chain is complete. If an intermediate certificate is missing from the PFX or the extracted PEM file, applications may fail to validate the connection. Use openssl x509 -in cert.pem -text -noout to inspect the certificate details and confirm the issuer matches your expected Certificate Authority.

Frequently Asked Questions

Can I import a PFX file directly into the Linux trust store without splitting it?

No, standard Linux trust stores do not accept binary PKCS#12/PFX files directly. You must convert the file to PEM format using OpenSSL and place the resulting certificate file in the appropriate directory before updating the CA bundle.

Why does my website still show a certificate error after importing the PFX on Windows?

This often happens if the private key is not marked as exportable or if the certificate was installed in the wrong store (e.g., User instead of LocalMachine). Verify the certificate appears in the correct store and that the private key is linked correctly in the Certificate Manager.

Is it safe to remove the password from the private key PEM file?

Removing the password simplifies automation but reduces security. If the key.pem file is accessed by an attacker, they can decrypt traffic immediately. Only remove the passphrase if you implement strict file permissions and other compensating controls.

What should I do if the security import command fails on macOS?

Ensure you are targeting the correct keychain database file, which is usually login.keychain-db on newer macOS versions. Also, verify that the key.pem file is properly formatted and not corrupted during the OpenSSL extraction process.

How can I verify the certificate was installed correctly on Linux?

Run openssl s_client -connect hostname:443 -servername hostname to see the certificate chain presented by the server. Alternatively, check the system trust store by listing certificates in /etc/ssl/certs or using keytool if managing Java applications.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More