Sunday, January 11, 2015

Linux - generating gpg key for rpm signing

Here how it goes. I wanted to create my own rpm for rootsh-1.5.3 after wanting to disable logging to syslog.

First things first, here's how you generate a gpg key.

[user@host~]$ gpg --gen-key
gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

gpg: keyring `/home/xxxxxx/.gnupg/secring.gpg' created
gpg: keyring `/home/xxxxxx/.gnupg/pubring.gpg' created
Please select what kind of key you want:
   (1) DSA and Elgamal (default)
   (2) DSA (sign only)
   (5) RSA (sign only)
Your selection? X
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is XXXX bits
Please specify how long the key should be valid.
         0 = key does not expire
       = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0) XX
Key expires at Day DD Mmm YYYY HH:MM:SS AM MYT
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) "

Real name: Xxxxxx Xxxxxx
Email address: xxxxxx@xxxxx.xxx
Comment:
You selected this USER-ID:
    "Xxxxxx Xxxxxx "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.


gpg: /home/xxxxxx/.gnupg/trustdb.gpg: trustdb created
gpg: key 2F74F867 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
gpg: next trustdb check due at YYYY-MM-DD
pub   2048R/2F74F867 2015-01-10 [expires: 2016-01-10]
      Key fingerprint = XXXX XXXX XXXX XXXX XXXX  XXXX XXXX XXXX XXXX XXXX 
uid                  Xxxxxx Xxxxxx

Note that this key cannot be used for encryption.  You may want to use
the command "--edit-key" to generate a subkey for this purpose.

And pick a long passphrase and remember them. The next time I will be doing would be to add a jpeg photo. It's actually unnecessary but I'll just doing for completeness sake. It's usually done when uploading gpg keys onto public key servers.

Downloaded a photo of myself and had it called me.jpg on my home directory.

[user@host ~]$ gpg --edit-key xxxxxx@xxxxx.xxx
gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Secret key is available.

pub  2048R/2F74F867  created: 2015-01-10  expires: 2016-01-10  usage: SC
                     trust: ultimate      validity: ultimate
[ultimate] (1). Xxxxxx Xxxxxx

Command> addphoto

Pick an image to use for your photo ID.  The image must be a JPEG file.
Remember that the image is stored within your public key.  If you use a
very large picture, your key will become very large as well!
Keeping the image close to 240x288 is a good size to use.

Enter JPEG filename for photo ID: /home/xxxxxx/me.jpg
This JPEG is really large (9181 bytes) !
Are you sure you want to use it? (y/N) n

Enter JPEG filename for photo ID: /home/xxxxxx/me.jpg
cannot open display:
Run 'eog --help' to see a full list of available command line options.
gpg: unable to display photo ID!
Is this photo correct (y/N/q)? y

You need a passphrase to unlock the secret key for
user: "Xxxxxx Xxxxxx "
XXXX-bit RSA key, ID XXXXXX, created YYYY-MM-DD


pub  XXXXX/XXXXXXXX  created: YYYY-MM-DD  expires: YYYY-MM-DD  usage: SC
                     trust: ultimate      validity: ultimate
[ultimate] (1). Xxxxxx Xxxxxx
[ unknown] (2)  [jpeg image of size 4936]

Command> save

To list of keys all available keys.

[user@host ~]$ gpg  --list-keys --fingerprint
/home/user/.gnupg/pubring.gpg
---------------------------------
pub   XXXXX/XXXXXXXX YYYY-MM-DD[expires: YYYY-MM-DD]
      Key fingerprint = XXXX XXXX XXXX XXXX XXXX  XXXX XXXX XXXX XXXX XXXX
uid                  Xxxxxx Xxxxxx 
uid                  [jpeg image of size 4936]

To list out the keys that has been installed:

[user@host ~]# rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n' 

No comments: