T The Triage ManualTechnical Guides for IT Emergencies
P4 · PKI & Certificate Management

Adding or Removing a Passphrase from an Existing OpenSSL Private Key

A private key generated without passphrase protection can have one added later using 'openssl rsa -aes256' without regenerating the key pair. Conversely, an existing passphrase can be removed by omitting the encryption flag from the same command. Both operations replace the original key file in-place and should be followed by restricting file permissions to 400.

Indicators

Likely causes

Diagnostic steps

  1. Verify the current state of the private key — run `openssl rsa -in your.key -text -noout`. If prompted for a passphrase, the key is already encrypted. If it outputs key details without prompting, the key is unencrypted.
  2. To ADD a passphrase with AES-256 encryption, run: `openssl rsa -aes256 -in your.key -out your.encrypted.key`. You will be prompted to enter and confirm a new passphrase. Avoid legacy algorithms such as -des or -des3.
  3. Replace the original key file with the newly encrypted version: `mv your.encrypted.key your.key`
  4. Restrict permissions on the key file to owner read-only: `chmod 400 your.key`
  5. To REMOVE a passphrase from an encrypted key, run: `openssl rsa -in your.key -out your.open.key`. You will be prompted for the current passphrase one final time. Omitting any encryption flag causes the output to be written unencrypted.
  6. Replace the original key with the unencrypted version and restrict permissions: `mv your.open.key your.key && chmod 400 your.key`
  7. Verify the operation succeeded by re-running `openssl rsa -in your.key -text -noout` and confirming whether or not a passphrase prompt appears as expected.

Resolution path

Prevention

Tools

References

opensslprivate-keypassphraseencryptionrsakey-managementaes256pkissl-tlssecurityhardeningcertificate-management