error message - openssl: command not found

13,381

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.

Share:
13,381

Related videos on Youtube

Michael Nash
Author by

Michael Nash

Updated on September 18, 2022

Comments

  • Michael Nash
    Michael Nash over 1 year

    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"
    else
      echo "Certificate is expired"
    fi
    

    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:

    usr/bin/openssl
    
    • Nasir Riley
      Nasir Riley over 4 years
      Add the output of apropos openssl | grep "OpenSSL command line tool" and locate openssl | grep /usr/bin to your question.
    • Panki
      Panki over 4 years
      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
    • steve
      steve over 4 years
      dpkg --listfiles openssl | more to see where it's dropped the openssl executable. It clearly isn't in your $PATH.
  • binarym
    binarym over 4 years
    @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
  • Michael Nash
    Michael Nash over 4 years
    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.