Ubuntu 16.04: GPGキーを作成する


1 rng-toolsでランダム値を更新する


Not enough random bytes available. Please do some other work to give


$ sudo apt install -y rng-tools
$ sudo rngd -r /dev/urandom

2 interactiveモードで作成する

gpg –gen-keyでGPGキーを作成します。

$ gpg --gen-key


gpg: keyring `/home/hiroom2/.gnupg/secring.gpg' created
gpg: keyring `/home/hiroom2/.gnupg/pubring.gpg' created

デフォルトの"(1) RSA and RSA"にします。

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection?


RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)

デフォルトの"key does not expire"にします。yを押します。

Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y


You need a user ID to identify your key; the software constructs the
user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name: hiroom2
Email address: hiroom2@example.com
Comment: hiroom2 gpg key


Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O


Enter passphrase:
Repeat passphrase:


generator a better chance to gain enough entropy.
gpg: /home/hiroom2/.gnupg/trustdb.gpg: trustdb created
gpg: key 65F355D9 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   2048R/65F355D9 2016-08-14
      Key fingerprint = 95CF BBE0 C638 93EB 7E77  C427 A093 6A22 65F3
uid                  hiroom2 (hiroom2 gpg key) <hiroom2@example.com>
sub   2048R/FEC8326F 2016-08-14

3 batchモードで作成する


$ cat <<EOF > gpg.txt
%pubring ${HOME}/.gnupg/pubring.gpg
%secring ${HOME}/.gnupg/secring.gpg
Key-Type: RSA
Subkey-Type: RSA
Key-Length: 2048
Subkey-Length: 2048
Expire-Date: 0
Name-Real: hiroom2
Name-Email: hiroom2@example.com
Name-Comment: hiroom2 gpg key
Passphrase: mypassphrase

gpg –gen-key –batchでGPGキーを作成します。

$ gpg --gen-key --batch gpg.txt