GoAdmio

openssl

Create a private key and certificate request (CSR) for a paid SSL certificate, install the certificate you receive, or remove a domain's SSL files

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/openssl handles paid SSL certificates, the ones you buy from a certificate authority (CA) rather than get free from Let's Encrypt. Getting one takes four steps, and the command covers three of them:

  1. Create a key and a CSR for the domain with /go/openssl <domain>.
  2. Send the CSR to the CA (outside GoAdmio).
  3. Save the files you get back from the CA in the domain's folder.
  4. Install them with /go/openssl <domain> install.

It can also remove a domain's SSL files with delete.

The command doesn't need sudo. If you aren't root, it runs itself again with sudo.


Quick start

# 1. Create the private key and the CSR
/go/openssl example.com

# 2. Show the CSR, and send it to your certificate authority
cat /etc/ssl/example.com/example.com.csr

# 3. Save the certificate as /etc/ssl/example.com/crt.pem
#    and the CA bundle as /etc/ssl/example.com/bundle.pem

# 4. Install the certificate
/go/openssl example.com install

Syntax

/go/openssl <domain>             # create a key and a CSR
/go/openssl <domain> install     # install the certificate
/go/openssl <domain> delete      # remove SSL files
/go/openssl all                  # create keys and CSRs for every domain

The domain always comes first, then the action.


Options

Argument Required Notes
<domain> Yes The domain of the hosting account. Use all to go through every domain.
install No Checks and installs the certificate files.
delete No Removes the SSL files and rebuilds the web server configuration.
(no action) No Creates the private key and the CSR.

Output

Action What you get
Create a CSR Nothing is printed. The files are saved in /etc/ssl/<domain>/.
install SSL Certificate installed successfully. and Certificate expires on: <date>
install with a problem Invalid Certificate., Invalid Certificate Authority Bundle., or Private Key and Certificate do not match.
delete Nothing, apart from the output of the web server rebuild and reload.

install, delete, and all always end with exit status 1, even when they work.

Every run is logged to /var/log/go/openssl.log with a timestamp and the arguments used.


Examples

# Create the key and the CSR for example.com
/go/openssl example.com
cat /etc/ssl/example.com/example.com.csr
# Install the certificate after saving crt.pem and bundle.pem
/go/openssl example.com install
# Remove the SSL files of a domain
/go/openssl example.com delete
# Create keys and CSRs for every domain
/go/openssl all

Troubleshooting

Symptom Likely cause Fix
No output after creating the CSR By design. Read the CSR with cat /etc/ssl/<domain>/<domain>.csr.
Invalid Certificate. crt.pem is missing or isn't a PEM certificate. Save the certificate from the CA as /etc/ssl/<domain>/crt.pem.
Invalid Certificate Authority Bundle. bundle.pem is missing or isn't a PEM certificate. Save the CA bundle as /etc/ssl/<domain>/bundle.pem.
Private Key and Certificate do not match. The certificate was issued for a different key, for example after the CSR was created again. The command deletes crt.pem, key.pem, and bundle.pem. Ask the CA to issue the certificate again for the CSR in <domain>.csr, or create a new CSR and start over.
The same message appears for a key that is not RSA The key check only works with RSA keys. Use a 2048-bit RSA key, which is what the command creates.
The key was replaced unexpectedly If either <domain>.key or <domain>.csr is missing, both are created again. Keep both files. Back them up after step 1.
The paid certificate is still used after delete delete removes cert.pem, privkey.pem, chain.pem, and bundle.pem, but not crt.pem or key.pem, which install uses. Remove crt.pem and key.pem by hand, then rebuild the configuration with conf.
The free Let's Encrypt certificate is gone after delete delete also removes /etc/letsencrypt/live/<domain>. Get a new one with ssl.
The CSR has the wrong company or country The subject is fixed in the script. See Details. Create your own CSR with openssl req, and save the key as <domain>.key.
all skipped a domain all only handles domains whose folder /home/<username>/www exists. Run the command for that domain by hand.
A folder with a wrong name appeared in /etc/ssl The arguments were in the wrong order, for example /go/openssl delete example.com. Put the domain first. Remove the stray folder.

Details

Files

All files are in /etc/ssl/<domain>/.

File Created by Meaning
<domain>.key Creating the CSR The private key (RSA 2048, no passphrase).
<domain>.csr Creating the CSR The certificate request to send to the CA.
crt.pem You The certificate from the CA.
bundle.pem You The CA's intermediate certificates.
key.pem install A copy of <domain>.key, made if key.pem doesn't exist.

Create a key and a CSR

If <domain>.key or <domain>.csr is missing, the command creates the folder (owned by root, mode 400) and runs openssl req to create a new 2048-bit key and a CSR. If both exist, nothing happens.

The CSR subject

The subject is fixed: /CN=<domain>/emailAddress=info@<domain>/O=My Company Name LTD./C=EG. Most CAs only use the domain name for basic certificates, but check it if your CA validates the company name or country.

Install

flowchart TD
    A["/go/openssl domain install"] --> B["Make key.pem from domain.key if needed"]
    B --> C{"crt.pem valid?"}
    C -- "No" --> X1["Invalid Certificate, exit 1"]
    C -- "Yes" --> D{"bundle.pem valid?"}
    D -- "No" --> X2["Invalid Certificate Authority Bundle, exit 1"]
    D -- "Yes" --> E{"Key matches the certificate?"}
    E -- "No" --> X3["Delete crt.pem, key.pem, bundle.pem"]
    E -- "Yes" --> F["Rebuild the Apache and Nginx configuration, reload"]

The command checks that both certificates can be read, and that the certificate and the key belong together by comparing their moduli. It doesn't check that the certificate has not expired or that it is for the right domain. It then rebuilds the Apache and Nginx configuration for the domain with apache and nginx, and reloads the web server with reload.

Delete

Removes cert.pem, privkey.pem, chain.pem, and bundle.pem from /etc/ssl/<domain>/, and the folder /etc/letsencrypt/live/<domain>. It then rebuilds the Apache and Nginx configuration and reloads the web server. The key, the CSR, and Let's Encrypt's archive and renewal files are not removed.

Files and requirements

Item Used for
/etc/ssl/<domain>/ The key, the CSR, and the certificate files.
/var/lib/sqlite/site.db The PHP version of the domain, and the account username for all.
openssl Creating the key and checking the certificate.
/var/log/go/openssl.log The command log.

See also

Command Description
ssl Install an SSL certificate for a domain in GoAdmio
installssl Install Certbot (the Let's Encrypt client) and its web server plugin
zerossl Install a ZeroSSL certificate via the command line
checkssl Check if SSL certificates are installed for all domains
mailssl Install SSL certificates for SMTP and IMAP
miniossl Install an SSL certificate for MinIO
https Redirect HTTP to HTTPS in GoAdmio
reload Reload PHP-FPM and the active web server