1

GnuPG documentation is not that great for a beginner like me and I coudn't find much detailed information ouside either, I hope you can give me some guidance about this:

I am developing a wrapper for the gpg command line tool. I would like to know if I can fit on only one command line all the input information needed to generate a key pair.

Currently I have to call: gpg --gen-key and input several other pieces of information like the key type, expiration info, name, email, and comment one at a time.

I'm couldn't figure out the gpg manual to assist on this, any tips are welcome.

0
4

I believe the answer can be found in this part of the manual: Unattended GPG key generation.

As an example:

cat <<EOF | gpg2 --batch --gen-key
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: Joe Tester
Name-Comment: with stupid passphrase
Name-Email: joe@foo.bar
Expire-Date: 20170115
Passphrase: abc
EOF
0
1

GnuPG 2.1.0 added the parameter --quick-generate-key, which allows creation of a new key with common options.

Slightly summarizing the documentation:

--quick-generate-key user-id [algo [usage [expire]]]

--quick-gen-key

This is a simple command to generate a standard key with one user id. In contrast to --generate-key the key is generated directly without the need to answer a bunch of prompts.

If algo or usage are given, only the primary key is created and no prompts are shown. To specify an expiration date but still create a primary and subkey use “default” or “future-default” for algo and “default” for usage.

The expire argument can be used to specify an expiration date for the key. Several formats are supported; commonly the ISO formats “YYYY-MM-DD” or “YYYYMMDDThhmmss” are used. To make the key expire in N seconds, N days, N weeks, N months, or N years use “seconds=N”, “Nd”, “Nw”, “Nm”, or “Ny” respectively. Not specifying a value, or using “-” results in a key expiring in a reasonable default interval. The values “never”, “none” can be used for no expiration date.

If this command is used with --batch, --pinentry-mode has been set to loopback, and one of the passphrase options (--passphrase, --passphrase-fd, or passphrase-file) is used, the supplied passphrase is used for the new key and the agent does not ask for it. To create a key without any protection --passphrase '' may be used.

Note that it is possible to create a primary key and a subkey using non-default algorithms by using “default” and changing the default parameters using the option --default-new-key-algo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.