Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to automate the following process with the openssl command:

I've been working along the lines of the following command (here wrapped in python):

local("echo -n | openssl s_client -connect -certform DER | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/")

but it doesn't give me what I expect.

share|improve this question
up vote 1 down vote accepted

Your sed command is only capturing openssl s_client's standard output, but the certificate comes with the other debugging information on standard error. Have you tried something like this?

openssl s_client -connect </dev/null 2>&1 |
  openssl x509 -outform DER >/tmp/
share|improve this answer
That worked. Thank you! – Danny Armstrong Jan 11 '13 at 6:39

You're probably seeing the lines which openssl outputs on stderr and are ignored by sed. You can just get rid of these before passing the output to sed:

% echo | openssl s_client -connect -certform DER 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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