Score:1

apt-key command: What is the difference among '--recv-key', '--recv-keys' and '--recv' options?

kz flag

For documentation purposes, about the apt-key command in many places I found these two variations:

sudo apt-key adv --keyserver       keyserver.ubuntu.com    --recv-keys PUBKEY
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv      PUBKEY

Observe the difference about the latest option --recv-keys and --recv. About the Ubuntu's official man at jammy apt-key(8) does mention only about:

   adv (deprecated)
       Pass advanced options to gpg. With adv **--recv-key** you can e.g. download key from
       keyservers directly into the trusted set of keys. Note that there are no checks
       performed, so it is easy to completely undermine the apt-secure(8) infrastructure if
       used without care.

And now from above see other option --recv-key (different as --recv-keys - it ends with s)

And at jammy gpg(1) does mention only about:

 --recv-keys keyIDs
        Import the keys with the given keyIDs from a keyserver.

Observation in the mentioned man appears the --recv-key term as content for other options but it does not exist as an option definition itself. ( consider to use the ctrl + f keys to search using the --recv as search term, it because there is a line with the --recv-key term split in 2 lines.)

Question

  • What is the difference among --recv-key, --recv-keys and --recv options?

If exists these 3 options, therefore each one has a specific purpose.

waltinator avatar
it flag
Read `man apt-key gpg`. `apt-key`uses `gpg` for key management.
Score:2
us flag

It's not obvious from the documentation, but gpg is one of those commands where you can pass a unique prefix of an option instead of having to type it out in full. If you had two options such as:

--some-long-option
--some-other-long-option

Then any of --some-l, --some-lo, --some-lon, etc. is enough to distinguish it from --some-other-long-option. So, you could use these abbreviated forms instead of always using --some-long-option.

This is implied by the documentation however, where it says that "the option may not be abbreviated" in gpg.conf (and some other options like --help, --version, etc. cannot be abbreviated either).

So all three of --recv, --recv-key and --recv-keys are equivalent.

mchid avatar
bo flag
It looks like the long option is `--receive-keys` to import keys from a keyserver.
Manuel Jordan avatar
kz flag
About _is one of those commands where you can pass a unique prefix of an option instead of having to type it out in full_ - is it a common standard? Is there a way to know explicitly through the `man` for each command if exists a special note/indication indicating if this feature is applied or not?
muru avatar
us flag
No, I don't think many tools "advertise" this feature because they usually rely on some library to do the parsing, so the behaviour may change from platform to platform. In this case, it might be using [the `getopt_long` function from glibc](https://unix.stackexchange.com/a/379993/70524), which is probably why the abbreviated forms aren't supported in the config file. I didn't even realise gpg had it until today.
muru avatar
us flag
Other tools that might support this are those developed in Go, whose standard library argument parsing also has the same feature. And in Vim, you can use abbreviations in *command mode* (not sure about options, though).
Manuel Jordan avatar
kz flag
Huge thanks for the valuable extra feedback.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.