TOOL: create self-signed SSL from command line

Hi,

I just wanted to share this in case it helps someone else. I’m pulling over quite a lot of domains from another server. I need to setup a self-signed SSL (until the site goes live, and we can then setup LetsEncrypt). What I was doing, is creating the self-signed cert from the GUI. However, this was a bit boring :wink: So I wrote a little script that will do it quicker:

create-self-signed-for-domain.sh

#!/bin/bash

domain=$1
email='[email protected]'

user_domain_is_in=""
locations_found=$(find /home/ -type d -name "$domain" -exec ls -ld {} \; | awk '{print $3}')
for location in $locations_found; do
    if [ "$location" != "root" ]; then
        user_domain_is_in="$location"
        break
    fi
done

# check if the user is valid!
if [ "$user_domain_is_in" == "" ]; then
    echo "ERROR: User not found!"
    exit 1
fi

echo "USER GRABBED: $user_domain_is_in"

cert=$(v-generate-ssl-cert "$domain" "$email" "US" "California" "San Francisco" "MyCompany LLC" "www.$domain")

path=($cert)
tmp_path="${path[-1]#Directory: }"

echo "TMP PATH: '$tmp_path'"

v-add-web-domain-ssl "$user_domain_is_in" "$domain" "$tmp_path"

Simply invoke with:

bash create-self-signed-for-domain.sh the_domain.com

This will save me a lot of time - so I thought I’d share it, in case it helps someone else :slight_smile: I’m not sure if its worth porting with the official repo, or not?

Change the value of $email to whatever you want

Cheers

Andy

2 Likes

Incase of Ubuntu 20.04 or higher or Debian 10 + it can be left empty :slight_smile:

1 Like

What can? :slight_smile: The email address?

Yes the email address :slight_smile:

Ah ok - I wasn’t aware of that (may as well leave it in though, in case people are using a different OS =))