14

In GPG, it possible to move a UID up or down in the list of UIDs in a PGP key?

I realize it is a purely cosmetic thing, but I may want to use this to show priority among my addresses, which one should be used first if possible.

pub   4096R/0xAABBD62D0BA66C66 2014-09-02
uid                 [ultimate] Mr. Foo Bar <fourth@example.com>
uid                 [ultimate] Mr. Foo Bar <first@example.com>
uid                 [ultimate] Mr. Foo Bar <third@example.com>
uid                 [ultimate] Mr. Foo Bar <second@example.com>
18

You can make a UID appear at the top of the list by making it primary. The top UID then gets moved down to the second slot, and likewise, everything else shifts one space downward. It seems as though this "shift" only happens once you save the changes to the key.

If you want to get the correct order, you need to repeat these steps starting with the UID you want showing up second-to-last, all the way until the item you want displayed as the top (first) UID.

The commands for doing this are (the text following $ and gpg> are what you type into the console):

$ gpg --edit-key 0xAABBD62D0BA66C66
gpg (GnuPG) 1.4.16; Copyright (C) 2013 Free Software Foundation, Inc.
 # irrelevant output removed #
[ultimate] (1). Mr. Foo Bar <fourth@example.com>
[ultimate] (2)  Mr. Foo Bar <first@example.com>
[ultimate] (3)  Mr. Foo Bar <third@example.com>
[ultimate] (4)  Mr. Foo Bar <second@example.com>
gpg> uid 3
[ultimate] (1). Mr. Foo Bar <fourth@example.com>
[ultimate] (2)  Mr. Foo Bar <first@example.com>
[ultimate] (3)* Mr. Foo Bar <third@example.com>
[ultimate] (4)  Mr. Foo Bar <second@example.com>
gpg> primary
[ultimate] (1)  Mr. Foo Bar <fourth@example.com>
[ultimate] (2)  Mr. Foo Bar <first@example.com>
[ultimate] (3)* Mr. Foo Bar <third@example.com>
[ultimate] (4)  Mr. Foo Bar <second@example.com>
gpg> save

Then rinse and repeat, working your way backwards from the second-to-last item all the way until the item you want displayed first in the list is the primary UID.

  • This isn't a very efficient solution, so I'm hoping someone else knows a better method. – IQAndreas Sep 2 '14 at 11:34
  • 3
    GPG isn't a very efficient solution—but it (technically) works! – conorsch Sep 22 '16 at 3:10
2

The only guaranteed behavior is that the primary UID is listed first.

Further rearranging them is not possible, and creates lots of clutter in the keyring, as each change requires new self-signatures.

Even if the UIDs show up in the "correct" order on your system, they do so because the order of database changes and the implementation of the database led to this, so a system seeing multiple changes at one time or using a different database backend is likely to behave differently.

1

The first shown UID is the one which either has the primary flag or the newest self-signature.

The others are shown in the order in which they are added to the keyring i.e. either the order of creation or the order of import.

Thus you can minimize the number of self-signatures by creating files which contain just one UID, delete the key (don't forget to backup the private keys first!), and import the UIDs in the desired order.

You can create these files with gpgsplit or by deleting all but one UID and exporting the remaining one, importing the file with all UIDs, delete all but another one and so on.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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