I am writing a simple script to check if the certificate for a website is valid. However, when I attempt to run the code in terminal, I receive an error message stating that the command openssl cannot be found. Here is the code:

if true | openssl s_client -connect www.google.com:443 2>/dev/null | \
  openssl x509 -noout -checkend 0; then
  echo "Certificate is not expired"
  echo "Certificate is expired"

When I attempt to run this code, I receive this output:

./check-certificates.sh: line 6:  openssl: command not found
Certificate is expired

The code runs, but it does not recognise openssl as a valid command, so it skips over the line of code where this is mentioned, and defaults to outputting "Certificate is expired".

When using sudo apt-get install openssl I receive this message:

openssl is already the newest version (1.0.2g-1ubuntu4.15).

So it looks like openssl has been successfully installed. I'm at a loss on how to fix this - does anybody have any ideas?

As requested, here is the output of apropos openssl | grep "OpenSSL command line tool":

openssl (1ssl)       - OpenSSL command line tool

And locate openssl | grep /usr/bin:

  • Add the output of apropos openssl | grep "OpenSSL command line tool" and locate openssl | grep /usr/bin to your question. Oct 4, 2019 at 9:28
  • Provide full path to openssl binary or add it to you PATH variable. You can find out where it is located by running whereis openssl
    – Panki
    Oct 4, 2019 at 9:28
  • 1
    dpkg --listfiles openssl | more to see where it's dropped the openssl executable. It clearly isn't in your $PATH.
    – steve
    Oct 4, 2019 at 9:29

1 Answer 1


Note the extra space in the error message:

./check-certificates.sh: line 6:  openssl: command not found

This means that the command that the shell is looking for isn’t openssl, it’s  openssl, probably with an unbreakable space pre-prended.

You need to edit your script to make absolutely sure that the space before openssl is a “normal” space, or even delete it.

See Why is this command not working: "ps aux | grep xscreensaver" for a similar instance with a bit more info.

  • Thanks for your suggestion - this did not resolve the problem, I still receive the same exact error message, including the space, when I deleted the spaces before and after the pipe. But you may be on to something regarding the extra space in the error message, that's likely the key to fix the problem Oct 4, 2019 at 10:09
  • @Stephen Kitt is right.... You just probably forgot one space, since openssl is called twice on the line with, for the two times, an extra unbreakable space, probably due to the fact that you hit space without releasing the alt-gr key... French keyboard, isn't it ? ;-p
    – binarym
    Oct 4, 2019 at 10:12
  • 1
    I fixed the problem - noob error. The main line of text is all on one line in my script, therefore there was a space after the /, causing the shell to add a space before the openssl command. Your comment helped me identify the problem though, thanks very much for your help. Oct 4, 2019 at 10:44

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.