OpenSUSE Leap 15: Create GPG key

Chromium and Google Chrome needs KDE Wallet to encrypt password file. KDE Wallet supports encryption with GPG key. This article describe how to create GPG key.

1 Create GPG key with KGpg

Run KGpg. Click "Next".

> kgpg

0001_WelcomeToTheKGpgAssistant.png

KGpg prompts for the gpg command path. You can use the default /usr/bin/gpg2. Click "Next".

0002_GnuPGBinary.png

KGpg asks wheather creating GPG config file or not. Click "Create Config".

0003_TheGnuPGConfigurationFileWasNotFound.png

KGpg prompts for GPG config file path. You can use the default ~/.gnupg/gpg.conf. Click "Next".

0004_ConfigurationFile.png

Click "Finish".

0005_Done.png

Input "Name", "Email" and "Comment". Click "OK".

0006_InputName.png

Input passphrase. Click "OK".

0007_EnterPassphrase.png

GPG key is created at ~/.gnupg. Click "OK" and close KGpg window.

0008_NewKeyPairCreated.png

2 Create GPG key with gpg command

Create GPG key with gpg command interactively.

> gpg --gen-key

Input name.

Real name: hiroom2

Input Email.

Email address: hiroom2@localhost

Type "O".

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

If X window is enabled, X window will popup. Input passphrase.

┌──────────────────────────────────────────────────────┐
│ Please enter the passphrase to                       │
│ protect your new key                                 │
│                                                      │
│ Passphrase: ________________________________________ │
│                                                      │
│       <OK>                              <Cancel>     │
└──────────────────────────────────────────────────────┘

Confirm passphrase.

┌──────────────────────────────────────────────────────┐
│ Please re-enter this passphrase                      │
│                                                      │
│ Passphrase: ________________________________________ │
│                                                      │
│       <OK>                              <Cancel>     │
└──────────────────────────────────────────────────────┘

GPG key is created at ~/.gnupg.

pub   rsa2048 2018-06-07 [SC] [expires: 2020-06-06]
      B7262B75DD4F7BFFEFC9ACF527362358E961C720
uid                      hiroom2 <hiroom2@localhost>
sub   rsa2048 2018-06-07 [E] [expires: 2020-06-06]

2.1 Create GPG key with gpg –batch option noninteractively

Specify gpg command setting file with –batch option.

#!/bin/sh


TMP=$(mktemp -t gpg.XXXXXX)
cat <<EOF > "${TMP}"
Key-Type: RSA
Subkey-Type: RSA
Key-Length: 2048
Subkey-Length: 2048
Expire-Date: 0
Name-Real: hiroom2
Name-Email: hiroom2@localhost
Name-Comment: hiroom2 GPG key
Passphrase: mypassword
%commit
EOF
gpg --gen-key --batch "${TMP}"
rm -f "${TMP}"