I can see the certificate with this command

openssl s_client -host {HOST} -port 443 -prexit -showcerts

How can I save the x509 cert of the website in a PEM - File?

  • man x509 should give enough clues, especially the -outform PEM option. – Deer Hunter Nov 15 '14 at 12:28
  • i think that -outformis just for converting files into PEM or DER files, but how can I download the x509 file? – user3653164 Nov 15 '14 at 12:35


echo "" | openssl s_client -host {HOST} -port 443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'  > cert.pem

then to get all certs in chain , a quick way could be

echo "" | openssl s_client -host {HOST} -port 443 -showcerts | awk '/BEGIN CERT/ {p=1} ; p==1; /END CERT/ {p=0}' > allcerts.pem
  • i tried that, but then i only get 1 certificate. but there are 4 or 5 certificates – user3653164 Nov 15 '14 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.