34

In gpg, is 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 <[email protected]>
uid                 [ultimate] Mr. Foo Bar <[email protected]>
uid                 [ultimate] Mr. Foo Bar <[email protected]>
uid                 [ultimate] Mr. Foo Bar <[email protected]>
Jonathan Cross
  • 248
  • 1
  • 10
IQAndreas
  • 10,145
  • 21
  • 59
  • 79

3 Answers3

36

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 <[email protected]>
[ultimate] (2)  Mr. Foo Bar <[email protected]>
[ultimate] (3)  Mr. Foo Bar <[email protected]>
[ultimate] (4)  Mr. Foo Bar <[email protected]>
gpg> uid 3
[ultimate] (1). Mr. Foo Bar <[email protected]>
[ultimate] (2)  Mr. Foo Bar <[email protected]>
[ultimate] (3)* Mr. Foo Bar <[email protected]>
[ultimate] (4)  Mr. Foo Bar <[email protected]>
gpg> primary
[ultimate] (1)  Mr. Foo Bar <[email protected]>
[ultimate] (2)  Mr. Foo Bar <[email protected]>
[ultimate] (3)* Mr. Foo Bar <[email protected]>
[ultimate] (4)  Mr. Foo Bar <[email protected]>
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.

IQAndreas
  • 10,145
  • 21
  • 59
  • 79
4

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.

Simon Richter
  • 4,409
  • 18
  • 20
2

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.

Hauke Laging
  • 88,146
  • 18
  • 125
  • 174