Skip to content

Commit ce5554c

Browse files
authored
Update gen-cert.sh
Generating Self-Sign Certificates for server SSL
1 parent 83dd69f commit ce5554c

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

gen-cert.sh

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,70 @@
11
#!/bin/bash
22

3-
#Required
4-
domain=$1
5-
commonname=$domain
6-
7-
#Change to your company details
8-
country=IN
9-
state=Bihar
10-
locality=Patna
11-
organization=raindigi.com
12-
organizationalunit=Engineering
13-
14-
15-
#Optional
16-
password=SecretePassword
17-
18-
if [ -z "$domain" ]
19-
then
20-
echo "Argument not present."
21-
echo "Useage $0 [common name]"
3+
# Required
4+
domain="localhost"
5+
commonname="$domain"
6+
7+
# Change to your company details
8+
country="IN"
9+
state="Bihar"
10+
locality="patna"
11+
organization="rollout.io"
12+
organizationalunit="Engineering"
13+
2214

15+
# Optional
16+
password="SecretePassword"
17+
18+
if [ -z "$domain" ]; then
19+
echo "Argument not present."
20+
echo "Usage $0 [common name]"
2321
exit 99
2422
fi
2523

2624
echo "Generating key request for $domain"
2725

2826
# Generate SSL/TLS certificates (valid for 365 days)
29-
30-
# openssl req -new -key ./certs/key.pem -out ./certs/csr.pem
31-
openssl genrsa -out ./etc/ssl/certs/$domain-key.pem
32-
33-
echo "Creating CSR"
34-
openssl req -new -key certs/$domain.pem -out certs/$domain-csr.pem -passin pass:$password \
27+
mkdir -p certificates
28+
openssl genrsa -out "./certificates/$domain-key.pem" 2048
29+
openssl req -new -key "./certificates/$domain-key.pem" -out "./certificates/$domain-csr.pem" -passin pass:"$password" \
3530
-subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email"
3631

37-
openssl x509 -req -days 365 -in ./etc/ssl/certs/$domain-csr.pem -signkey ./etc/ssl/certs/$domain-key.pem -out ./etc/ssl/certs/$domain-cert.pem
32+
openssl x509 -req -days 365 -in "./certificates/$domain-csr.pem" -signkey "./certificates/$domain-key.pem" -out "./certificates/$domain-cert.pem"
3833

39-
#Generate a key
40-
openssl genrsa -des3 -passout pass:$password -out ./etc/ssl/certs/$domain.key 2048 -noout
34+
# Generate a key
35+
openssl genrsa -des3 -passout pass:"$password" -out "./certificates/$domain.key" 2048
4136

42-
#Remove passphrase from the key. Comment the line out to keep the passphrase
37+
# Remove passphrase from the key. Comment the line out to keep the passphrase
4338
echo "Removing passphrase from key"
44-
openssl rsa -in etc/ssl/certs/$domain.key -passin pass:$password -out etc/ssl/certs/$domain.key
39+
openssl rsa -in "./certificates/$domain.key" -passin pass:"$password" -out "./certificates/$domain.key"
4540

46-
#Create the request
41+
# Create the request
4742
echo "Creating CSR"
48-
openssl req -new -key ./etc/ssl/certs/$domain.key -out ./etc/ssl/certs/$domain.csr -passin pass:$password \
43+
openssl req -new -key "./certificates/$domain.key" -out "./certificates/$domain.csr" -passin pass:"$password" \
4944
-subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email"
5045

46+
# Generate certificate
47+
openssl x509 -req -days 365 -in "./certificates/$domain-csr.pem" -signkey "./certificates/$domain.key" -out "./certificates/$domain-cert.pem"
48+
49+
# Rename the certificate file to have a .crt extension
50+
mv "./certificates/$domain-cert.pem" "./certificates/$domain.crt"
51+
5152
echo "---------------------------"
5253
echo "-----Below is your CSR-----"
5354
echo "---------------------------"
5455
echo
55-
cat etc/ssl/certs/$domain.csr
56+
cat "./certificates/$domain-csr.pem"
5657

5758
echo
5859
echo "---------------------------"
5960
echo "-----Below is your Key-----"
6061
echo "---------------------------"
6162
echo
62-
cat ./etc/ssl/certs/$domain.key
63+
cat "./certificates/$domain.key"
64+
65+
echo
66+
echo "---------------------------"
67+
echo "-----Below is your CRT-----"
68+
echo "---------------------------"
69+
echo
70+
cat "./certificates/$domain.crt"

0 commit comments

Comments
 (0)