In this post we are going to learn how to generate a GPG key without having to answer prompts so it can be added to a script if desired.

We start by creating a file where we’ll write the details for our key. This will be the content of the file:

1
2
3
4
5
6
7
8
9
10
11
%echo Generating GPG key
Key-Type: default
Key-Type: RSA
Key-Length: 3072
Subkey-Type: RSA
Subkey-Length: 3072
Name-Real: Carlos Sanchez
Name-Email: carlos@sanchez.mex
%no-protection
%commit
%echo done

And then we can use this command to generate the key:

1
gpg --batch --gen-key <file path>

We can find all the options for generating the key in unattended key generation documentation.

[ automation  security  ]
Update let’s encrypt certificate without restarting your server