OPENSSL Save x509 certificate of a website

Solution 1:

try

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