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
The file is a certificate, not a raw key
common"-----BEGIN CERTIFICATE-----" is an X.509 certificate that contains a public key but is not one. Commands expecting a bare SPKI (-pubin) refuse it; the key must be extracted first.
An OpenSSH key where PEM is expected
commonOne-line "ecdsa-sha2-nistp256 AAAA... user@host" entries (authorized_keys format) are OpenSSH's own encoding, not PEM/DER. OpenSSL cannot read them without conversion.
Private key passed with -pubin
commonThe -pubin flag promises the input is a public key. OpenSSL 1.1 and 3.0 refuse "-----BEGIN PRIVATE KEY-----" under it — drop the flag or derive the public half first. (OpenSSL 3.5 and later quietly read the public half instead.)
DER file read as PEM
occasionalOn OpenSSL 1.1, binary .der/.cer files need -inform der: PEM parsing of binary data finds no BEGIN line and fails. OpenSSL 3 detects DER on its own.
How to fix it
- 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.
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.
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