curl: (58) unable to set private key file: ‘server.key’ type PEM

This article was published 5 years ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

This took me far too long to work out.

I kept getting the following error whilst trying to sign a cURL request:

curl: (58) unable to set private key file: 'server.key' type PEM

Google kept sending me to this StackOverflow page which is correct, but was not the issue that I was having. I tried placing both key and cert in one file and using --cert, and using separate files and sending --cert and --key. The actual issue is that I was sending the wrong certificate file. This meant that cURL was looking for a private key that belongs to that certificate and couldn’t find it (leading the to above error)

To ensure that your certificate and key match, you can use the following commands:

$ openssl x509 -noout -modulus -in server.crt | openssl md5
$ openssl rsa -noout -modulus -in server.key | openssl md5

You should see something that looks like the following:

(stdin)= 47f0c86371b31432504f195357cf2947

If the two values don’t match, you’re not using the correct combination.

Thoughts on this post

duolong 2018-10-15

thank you very much,support a direction

Thanks! It helped a lot!

Facu 2019-08-08

Muchas gracias, super util.

Raphaël T. 2019-09-11

Thank you. It helper a lot.

Palm 2019-10-18

Thank you, help me troubleshooting an issue.

Esmeraldo Hilongos Jr 2019-12-10

Thank you very much it helper a lot

Leave a comment?