20

Is there a common best practice for naming exported public and private GPG keys when exporting them or otherwise storing them as files?

I know that GnuPG doesn’t care what keys are named when you import them. However, there must be some naming conventions for exporting. There always is for this sort of thing. I just can’t find a clear answer myself here or through Google.

I imagine there might not be a common best practice for naming private keys. In server environments, the private key seldom gets exported. But for personal communication encryption, a private key needs to be backed up, and possibly imported on a new computer. Therefore, it must be exported. In theory, you are the only person who will ever see the private key file and know what it is, so there is no need for a “best practice” naming convention. But the public key file must be shared and so there ought to be some common best practice out there.

Suppose I just created a new key pair: Bruce Wayne <[email protected]>.

Then I export the private and public keys as ASCII-armored files—the private key to be stored somewhere secure for backup and the public key to be shared with people.

What should I name the files? What extension should I use?

Generically…
public.key
private.key

Using the UID “Real Name”…
brucewayne-public.asc
brucewayne-private.asc

Using the UID email address…
[email protected]
[email protected]

When keys are generated, there’s an eight (hex) character ID that’s displayed. I have seen a public key use this as the filename.

~ # gpg --list-keys
/root/.gnupg/pubring.kbx
------------------------
pub   rsa2048/1234ABCD 2016-08-20 [SC]
uid         [ultimate] Bruce Wayne <[email protected]>
sub   rsa2048/5678EABC 2016-08-20 [E]

If there is any common best practice, please let me know. And, if possible, point me to any documentation or manual that uses it.

1
  • I edited the title and opening sentence of your question slightly to clarify that your question is about saving keys to files on disk, as opposed to the name embedded in the key as the user ID. If you feel that my edit changed the intent of your post, feel free to either edit further or to roll back the edit.
    – user
    Commented Aug 20, 2016 at 17:27

1 Answer 1

18

While obviously it's very hard to prove a negative, I think that the reason why you have found no such "common best practice" is that none exists.

The key itself doesn't care about its file name. What's more, there are ways to deal with exported keys that don't ever involve any files on a file system at all! Consider something relatively trivial, such as gpg --export 0xDEADBEEF | ssh [email protected] gpg --import.

You should however name the exported key file such that you have some idea of what key it contains, since the exported file itself (ironically enough, more so if the file is ASCII armored than if it is not) won't hold that information in a readily readable format unless you edit it in yourself (for example, in the Comment: field of an ASCII armored data blob).

For publication, the hexadecimal key ID is usually a good place to start because it's reasonably unique, particularly if you use the full 64-bit key ID or even the fingerprint (which is practically, but not theoretically, guaranteed to be unique).

For personal storage, or to for example e-mail the public key to a correspondent, you usually want to be able to tell keys apart yourself, but don't really care about global uniqueness. Thus, something that identifies the key to you is likely a good place to start; thus, you might start by looking at information such as the associated name, the associated e-mail address, generation or expiration date, or something along those lines. If you generate a new key once every 18 months, for example, the generation date might be a reasonable thing to include in the file names, because it tells you about the chronology of the keys as well as which you could expect to be used for a specific message.

I have seen a variety of naming conventions to differentiate between the private and public portions of the key, but the bottom line there is that it really doesn't matter at all as long as you can tell with no risk of ambiguity which file is which. If you want to append -private and -public before the file name extension, or if you want to name one .asc and the other .private, or whichever scheme you prefer, really doesn't matter at all: just pick one that makes it obvious to you which file is which.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .