Skip to content
ecdsa.com
OpenSSL CLI (openssl pkey / ec / rsa / dgst)OpenSSL CLI

Error message

unable to load Public Key

OpenSSL 1.1.x wording; still the most-quoted form. OpenSSL 3.0 prints "Could not read key of Public Key from cert.pem", OpenSSL 3.5 and later "Could not find private key of Public Key from cert.pem" (reproduced on 3.0.2 and 3.6.4) — same failure, new phrasing.

What it means

The openssl command tried to read a public key from the file you named and found nothing it recognizes as one. The file exists — its content is the problem: a different object type (certificate, private key, SSH key), the wrong encoding, or not a key at all.

Why it happens

How to fix it

  1. 1.

    Extract the key from a certificate

    One command produces the SPKI public key PEM that -pubin commands expect.

    bash
    openssl x509 -in cert.pem -pubkey -noout > pubkey.pem
    openssl pkey -pubin -in pubkey.pem -noout -text   # now loads
  2. 2.

    Convert an OpenSSH key to PEM

    ssh-keygen exports an authorized_keys-format entry as a standard BEGIN PUBLIC KEY (SPKI) PEM — ssh-keygen calls this format PKCS8.

    bash
    ssh-keygen -f id_ecdsa.pub -e -m pkcs8 > pubkey.pem
  3. 3.

    Derive the public half from a private key

    If the file is actually the private key, don't use -pubin — derive the public key.

    bash
    openssl pkey -in private.pem -pubout -out pubkey.pem

Related errors

Browse the full signature error database