1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| NAME=my.domain.com
openssl genrsa -out $NAME.key 2048
openssl req -new -key $NAME.key -out $NAME.csr \ -subj "/C=CN/ST=Shanghai/L=Shanghai/O=/OU=/CN=$NAME"
cat >$NAME.ext <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = $NAME # Be sure to include the domain name here because Common Name is not so commonly honoured by itself DNS.2 = bar.$NAME # Optionally, add additional domains (I've added a subdomain here) IP.1 = 1.2.3.4 # Optionally, add an IP address (if the connection which you have planned requires it) EOF
openssl x509 -req -in $NAME.csr -CA myCA.pem -CAkey myCA.key -CAcreateserial \ -out $NAME.crt -days 825 -sha256 -extfile $NAME.ext
cat $NAME.crt $NAME.key >$NAME.pem
|