I found in https://www.gnupg.org/documentation/manuals/gnupg/Unattended-GPG-key-generation.html#Unattended-GPG-key-generation method to generate gpg keys without user interaction, but it doesn't seem to work.
My script is:
#!/usr/bin/env bash
rm -rf .gnupg
mkdir -m 0700 .gnupg
touch .gnupg/gpg.conf
chmod 600 .gnupg/gpg.conf
tail -n +4 /usr/share/gnupg2/gpg-conf.skel > .gnupg/gpg.conf
touch .gnupg/{pub,sec}ring.gpg
cat >.gnupg/foo <<EOF
%echo Generating a basic OpenPGP key
Key-Type: RSA
Key-Length: 2048
Subkey-Type: RSA
Subkey-Length: 2048
Name-Real: User 1
Name-Comment: User 1
Name-Email: user@1.com
Expire-Date: 0
Passphrase: kljfhslfjkhsaljkhsdflgjkhsd
%pubring foo.pub
%secring foo.sec
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
gpg2 --verbose --batch --gen-key .gnupg/foo
When I run it, it shows:
=$ ./gen.keys.sh
gpg: Generating a basic OpenPGP key
gpg: no running gpg-agent - starting one
gpg: writing public key to `foo.pub'
gpg: writing secret key to `foo.sec'
But then it just hangs.
When I check, in the mean time, ps tree for this user, I see:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
tstpg 22603 0.0 0.0 24108 5688 pts/9 Ss 14:59 0:00 -bash
tstpg 22624 0.0 0.0 13688 3168 pts/9 S+ 14:59 0:00 \_ bash ./gen.keys.sh
tstpg 22632 0.2 0.0 27428 3676 pts/9 SL+ 14:59 0:00 \_ gpg2 --verbose --batch --gen-key .gnupg/foo
tstpg 22634 0.3 0.0 18072 2884 pts/9 SL+ 14:59 0:00 \_ gpg-agent --server
In ~/.gnupg/gpg.conf there is no mention about agent, and I have no idea what it's trying to do.
The foo.pub/foo.sec files are generated in home dir, but are empty.
What am I missing? How to generate the key without any kind of user interaction?
Versions:
- gpg (GnuPG) 2.0.26
- libgcrypt 1.6.2