Create a secrets file:
touch ~/.secret
Make sure it looks like this:
#!/bin/bash
PASSPHRASE=mysecretpassphrase
And source it:
. ~/.secret
openssl genrsa -des3 -passout pass:$PASSPHRASE -out server.pass.key 2048;
openssl rsa -passin pass:$PASSPHRASE -in server.pass.key -out server.key;
openssl req -new -key server.key -out server.csr;
openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt;
# Remove the unencrypted private key
rm server.key
Test your generated and encrypted private key:
openssl rsa -in server.pass.key -text