Why does the apt-key man page advise against using its add command?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












The Ubuntu man page for apt-key includes the following note regarding apt-key add:




Note: Instead of using this command a keyring should be placed
directly in the /etc/apt/trusted.gpg.d/ directory with a
descriptive name and either "gpg" or "asc" as file extension.




I don't think I've ever seen this advice anywhere else. Most projects that host their own repositories say to download their key file and add it with apt-key.



  1. What is the motivation behind this advice?

  2. Is this an Ubuntu-ism, or does it apply to any APT-based distro?









share|improve this question























  • Possible duplicate of What is the benefit of /etc/apt/sources.list.d over /etc/apt/sources.list
    – DopeGhoti
    Aug 16 at 22:27










  • Not an actual duplicate per se; but the underlying question (why use .d directories?) is the same.
    – DopeGhoti
    Aug 16 at 22:28






  • 3




    It's not a duplicate at all, because the actual answer is not to do with the desirability or otherwise of .d directories.
    – JdeBP
    Aug 17 at 8:05














up vote
6
down vote

favorite












The Ubuntu man page for apt-key includes the following note regarding apt-key add:




Note: Instead of using this command a keyring should be placed
directly in the /etc/apt/trusted.gpg.d/ directory with a
descriptive name and either "gpg" or "asc" as file extension.




I don't think I've ever seen this advice anywhere else. Most projects that host their own repositories say to download their key file and add it with apt-key.



  1. What is the motivation behind this advice?

  2. Is this an Ubuntu-ism, or does it apply to any APT-based distro?









share|improve this question























  • Possible duplicate of What is the benefit of /etc/apt/sources.list.d over /etc/apt/sources.list
    – DopeGhoti
    Aug 16 at 22:27










  • Not an actual duplicate per se; but the underlying question (why use .d directories?) is the same.
    – DopeGhoti
    Aug 16 at 22:28






  • 3




    It's not a duplicate at all, because the actual answer is not to do with the desirability or otherwise of .d directories.
    – JdeBP
    Aug 17 at 8:05












up vote
6
down vote

favorite









up vote
6
down vote

favorite











The Ubuntu man page for apt-key includes the following note regarding apt-key add:




Note: Instead of using this command a keyring should be placed
directly in the /etc/apt/trusted.gpg.d/ directory with a
descriptive name and either "gpg" or "asc" as file extension.




I don't think I've ever seen this advice anywhere else. Most projects that host their own repositories say to download their key file and add it with apt-key.



  1. What is the motivation behind this advice?

  2. Is this an Ubuntu-ism, or does it apply to any APT-based distro?









share|improve this question















The Ubuntu man page for apt-key includes the following note regarding apt-key add:




Note: Instead of using this command a keyring should be placed
directly in the /etc/apt/trusted.gpg.d/ directory with a
descriptive name and either "gpg" or "asc" as file extension.




I don't think I've ever seen this advice anywhere else. Most projects that host their own repositories say to download their key file and add it with apt-key.



  1. What is the motivation behind this advice?

  2. Is this an Ubuntu-ism, or does it apply to any APT-based distro?






apt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 17 at 12:36









GAD3R

22.8k154895




22.8k154895










asked Aug 16 at 21:19









Andrew

18215




18215











  • Possible duplicate of What is the benefit of /etc/apt/sources.list.d over /etc/apt/sources.list
    – DopeGhoti
    Aug 16 at 22:27










  • Not an actual duplicate per se; but the underlying question (why use .d directories?) is the same.
    – DopeGhoti
    Aug 16 at 22:28






  • 3




    It's not a duplicate at all, because the actual answer is not to do with the desirability or otherwise of .d directories.
    – JdeBP
    Aug 17 at 8:05
















  • Possible duplicate of What is the benefit of /etc/apt/sources.list.d over /etc/apt/sources.list
    – DopeGhoti
    Aug 16 at 22:27










  • Not an actual duplicate per se; but the underlying question (why use .d directories?) is the same.
    – DopeGhoti
    Aug 16 at 22:28






  • 3




    It's not a duplicate at all, because the actual answer is not to do with the desirability or otherwise of .d directories.
    – JdeBP
    Aug 17 at 8:05















Possible duplicate of What is the benefit of /etc/apt/sources.list.d over /etc/apt/sources.list
– DopeGhoti
Aug 16 at 22:27




Possible duplicate of What is the benefit of /etc/apt/sources.list.d over /etc/apt/sources.list
– DopeGhoti
Aug 16 at 22:27












Not an actual duplicate per se; but the underlying question (why use .d directories?) is the same.
– DopeGhoti
Aug 16 at 22:28




Not an actual duplicate per se; but the underlying question (why use .d directories?) is the same.
– DopeGhoti
Aug 16 at 22:28




3




3




It's not a duplicate at all, because the actual answer is not to do with the desirability or otherwise of .d directories.
– JdeBP
Aug 17 at 8:05




It's not a duplicate at all, because the actual answer is not to do with the desirability or otherwise of .d directories.
– JdeBP
Aug 17 at 8:05










2 Answers
2






active

oldest

votes

















up vote
6
down vote



accepted










Those projects have outdated instructions. I know this because I publish a Debian repository and I updated my instructions when I found out about the changes in Debian 9 APT. Indeed, this part of the manual is now out of date, as it is the wrong directory.



This is not really to do with .d directories and more to do with preventing a cross-site vulnerability in APT. The older system used separate keyring files for convenience, but this is now a necessity for security; your security.



This is the vulnerability. Consider two repository publishers, A and B. In the world of Debian 8 and before, both publishers' keys went in the single global keyring on users' machines. If publisher A could somehow arrange to supplant the repository WWW site of publisher B, then A could publish subversive packages, signed with A's own key, which APT would happily accept and install. A's key is, after all, trusted globally for all repositories.



The mitigation is for users to use separate keyrings for individual publishers, and to reference those keyrings with individual Signed-By settings in their repository definitions. Specifically, publisher A's key is only used in the Signed-By of repository A and publisher B's key is only used in the Signed-By of repository B. This way, if publisher A supplants publisher B's repository, APT will not accept the subversive packages from it since they and the repository are signed by publisher A's key not by publisher B's.



The /etc/apt/trusted.gpg.d mechanism at hand is an older Poor Man's somewhat flawed halfway house towards this, from back in 2005 or so, that is not quite good enough. It sets up the keyring in a separate file, so that it can be packaged up and just installed in one step by a package manager (or downloaded with fetch/curl/wget) as any other file. (The package manager handles preventing publisher A's special this-is-my-repository-keyring package from installing over publisher B's, in the normal way that it handles file conflicts between packages in general.) But it still adds it to the set of keys that is globally trusted for all repositories. The full mechanism that exists now uses separate, not globally trusted, keyring files in /usr/share/keyrings/.



My instructions are already there. ☺ There are moves afoot to move Debian's own repositories to this mechanism, so that they no longer use globally trusted keys either. You might want to have a word with those "most projects" that you found. After all, they are currently instructing you to hand over global access to APT on your machine to them.



Further reading



  • Daniel Kahn Gillmor (2017-05-02). Please ship release-specific keys separately outside of /etc/apt/trusted.gpg.d/. Debian bug #861695.

  • Daniel Kahn Gillmor (2017-07-27). debian sources.list entries should have signed-by options pointing to specific keys. Debian bug #877012.


  • "Sources.list entry". Instructions to connect to a third-party repository. Debian wiki. 2018.

  • Why isn't it a security risk to add to sources.list?

  • Debian 9, APT, and "GPG error: ... InRelease: The following signatures were invalid:"





share|improve this answer





























    up vote
    1
    down vote













    apt-key del takes the keyid, which is a meaningless hash of the key.



    It is simpler if you can uninstall keys using a meaningful name... like a filename.



    As JdeBP says, this works nicely with trusted key files that are installed as part of a debian package. I think it can also be nicer when you've manually installed a key file.



    In the new mechanism which is currently in "initial testing", this is further simplified. You only have to remove/disable one thing: the repository (in sources.list / sources.list.d). That will automatically stop allowing the key configured for that repo (unless it was also used by another repo).



    I don't know how to take advantage of the new mechanism for security. I just assume that I need to trust someone if I use their package. The package install process is still running as root :-).






    share|improve this answer






















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463072%2fwhy-does-the-apt-key-man-page-advise-against-using-its-add-command%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      6
      down vote



      accepted










      Those projects have outdated instructions. I know this because I publish a Debian repository and I updated my instructions when I found out about the changes in Debian 9 APT. Indeed, this part of the manual is now out of date, as it is the wrong directory.



      This is not really to do with .d directories and more to do with preventing a cross-site vulnerability in APT. The older system used separate keyring files for convenience, but this is now a necessity for security; your security.



      This is the vulnerability. Consider two repository publishers, A and B. In the world of Debian 8 and before, both publishers' keys went in the single global keyring on users' machines. If publisher A could somehow arrange to supplant the repository WWW site of publisher B, then A could publish subversive packages, signed with A's own key, which APT would happily accept and install. A's key is, after all, trusted globally for all repositories.



      The mitigation is for users to use separate keyrings for individual publishers, and to reference those keyrings with individual Signed-By settings in their repository definitions. Specifically, publisher A's key is only used in the Signed-By of repository A and publisher B's key is only used in the Signed-By of repository B. This way, if publisher A supplants publisher B's repository, APT will not accept the subversive packages from it since they and the repository are signed by publisher A's key not by publisher B's.



      The /etc/apt/trusted.gpg.d mechanism at hand is an older Poor Man's somewhat flawed halfway house towards this, from back in 2005 or so, that is not quite good enough. It sets up the keyring in a separate file, so that it can be packaged up and just installed in one step by a package manager (or downloaded with fetch/curl/wget) as any other file. (The package manager handles preventing publisher A's special this-is-my-repository-keyring package from installing over publisher B's, in the normal way that it handles file conflicts between packages in general.) But it still adds it to the set of keys that is globally trusted for all repositories. The full mechanism that exists now uses separate, not globally trusted, keyring files in /usr/share/keyrings/.



      My instructions are already there. ☺ There are moves afoot to move Debian's own repositories to this mechanism, so that they no longer use globally trusted keys either. You might want to have a word with those "most projects" that you found. After all, they are currently instructing you to hand over global access to APT on your machine to them.



      Further reading



      • Daniel Kahn Gillmor (2017-05-02). Please ship release-specific keys separately outside of /etc/apt/trusted.gpg.d/. Debian bug #861695.

      • Daniel Kahn Gillmor (2017-07-27). debian sources.list entries should have signed-by options pointing to specific keys. Debian bug #877012.


      • "Sources.list entry". Instructions to connect to a third-party repository. Debian wiki. 2018.

      • Why isn't it a security risk to add to sources.list?

      • Debian 9, APT, and "GPG error: ... InRelease: The following signatures were invalid:"





      share|improve this answer


























        up vote
        6
        down vote



        accepted










        Those projects have outdated instructions. I know this because I publish a Debian repository and I updated my instructions when I found out about the changes in Debian 9 APT. Indeed, this part of the manual is now out of date, as it is the wrong directory.



        This is not really to do with .d directories and more to do with preventing a cross-site vulnerability in APT. The older system used separate keyring files for convenience, but this is now a necessity for security; your security.



        This is the vulnerability. Consider two repository publishers, A and B. In the world of Debian 8 and before, both publishers' keys went in the single global keyring on users' machines. If publisher A could somehow arrange to supplant the repository WWW site of publisher B, then A could publish subversive packages, signed with A's own key, which APT would happily accept and install. A's key is, after all, trusted globally for all repositories.



        The mitigation is for users to use separate keyrings for individual publishers, and to reference those keyrings with individual Signed-By settings in their repository definitions. Specifically, publisher A's key is only used in the Signed-By of repository A and publisher B's key is only used in the Signed-By of repository B. This way, if publisher A supplants publisher B's repository, APT will not accept the subversive packages from it since they and the repository are signed by publisher A's key not by publisher B's.



        The /etc/apt/trusted.gpg.d mechanism at hand is an older Poor Man's somewhat flawed halfway house towards this, from back in 2005 or so, that is not quite good enough. It sets up the keyring in a separate file, so that it can be packaged up and just installed in one step by a package manager (or downloaded with fetch/curl/wget) as any other file. (The package manager handles preventing publisher A's special this-is-my-repository-keyring package from installing over publisher B's, in the normal way that it handles file conflicts between packages in general.) But it still adds it to the set of keys that is globally trusted for all repositories. The full mechanism that exists now uses separate, not globally trusted, keyring files in /usr/share/keyrings/.



        My instructions are already there. ☺ There are moves afoot to move Debian's own repositories to this mechanism, so that they no longer use globally trusted keys either. You might want to have a word with those "most projects" that you found. After all, they are currently instructing you to hand over global access to APT on your machine to them.



        Further reading



        • Daniel Kahn Gillmor (2017-05-02). Please ship release-specific keys separately outside of /etc/apt/trusted.gpg.d/. Debian bug #861695.

        • Daniel Kahn Gillmor (2017-07-27). debian sources.list entries should have signed-by options pointing to specific keys. Debian bug #877012.


        • "Sources.list entry". Instructions to connect to a third-party repository. Debian wiki. 2018.

        • Why isn't it a security risk to add to sources.list?

        • Debian 9, APT, and "GPG error: ... InRelease: The following signatures were invalid:"





        share|improve this answer
























          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          Those projects have outdated instructions. I know this because I publish a Debian repository and I updated my instructions when I found out about the changes in Debian 9 APT. Indeed, this part of the manual is now out of date, as it is the wrong directory.



          This is not really to do with .d directories and more to do with preventing a cross-site vulnerability in APT. The older system used separate keyring files for convenience, but this is now a necessity for security; your security.



          This is the vulnerability. Consider two repository publishers, A and B. In the world of Debian 8 and before, both publishers' keys went in the single global keyring on users' machines. If publisher A could somehow arrange to supplant the repository WWW site of publisher B, then A could publish subversive packages, signed with A's own key, which APT would happily accept and install. A's key is, after all, trusted globally for all repositories.



          The mitigation is for users to use separate keyrings for individual publishers, and to reference those keyrings with individual Signed-By settings in their repository definitions. Specifically, publisher A's key is only used in the Signed-By of repository A and publisher B's key is only used in the Signed-By of repository B. This way, if publisher A supplants publisher B's repository, APT will not accept the subversive packages from it since they and the repository are signed by publisher A's key not by publisher B's.



          The /etc/apt/trusted.gpg.d mechanism at hand is an older Poor Man's somewhat flawed halfway house towards this, from back in 2005 or so, that is not quite good enough. It sets up the keyring in a separate file, so that it can be packaged up and just installed in one step by a package manager (or downloaded with fetch/curl/wget) as any other file. (The package manager handles preventing publisher A's special this-is-my-repository-keyring package from installing over publisher B's, in the normal way that it handles file conflicts between packages in general.) But it still adds it to the set of keys that is globally trusted for all repositories. The full mechanism that exists now uses separate, not globally trusted, keyring files in /usr/share/keyrings/.



          My instructions are already there. ☺ There are moves afoot to move Debian's own repositories to this mechanism, so that they no longer use globally trusted keys either. You might want to have a word with those "most projects" that you found. After all, they are currently instructing you to hand over global access to APT on your machine to them.



          Further reading



          • Daniel Kahn Gillmor (2017-05-02). Please ship release-specific keys separately outside of /etc/apt/trusted.gpg.d/. Debian bug #861695.

          • Daniel Kahn Gillmor (2017-07-27). debian sources.list entries should have signed-by options pointing to specific keys. Debian bug #877012.


          • "Sources.list entry". Instructions to connect to a third-party repository. Debian wiki. 2018.

          • Why isn't it a security risk to add to sources.list?

          • Debian 9, APT, and "GPG error: ... InRelease: The following signatures were invalid:"





          share|improve this answer














          Those projects have outdated instructions. I know this because I publish a Debian repository and I updated my instructions when I found out about the changes in Debian 9 APT. Indeed, this part of the manual is now out of date, as it is the wrong directory.



          This is not really to do with .d directories and more to do with preventing a cross-site vulnerability in APT. The older system used separate keyring files for convenience, but this is now a necessity for security; your security.



          This is the vulnerability. Consider two repository publishers, A and B. In the world of Debian 8 and before, both publishers' keys went in the single global keyring on users' machines. If publisher A could somehow arrange to supplant the repository WWW site of publisher B, then A could publish subversive packages, signed with A's own key, which APT would happily accept and install. A's key is, after all, trusted globally for all repositories.



          The mitigation is for users to use separate keyrings for individual publishers, and to reference those keyrings with individual Signed-By settings in their repository definitions. Specifically, publisher A's key is only used in the Signed-By of repository A and publisher B's key is only used in the Signed-By of repository B. This way, if publisher A supplants publisher B's repository, APT will not accept the subversive packages from it since they and the repository are signed by publisher A's key not by publisher B's.



          The /etc/apt/trusted.gpg.d mechanism at hand is an older Poor Man's somewhat flawed halfway house towards this, from back in 2005 or so, that is not quite good enough. It sets up the keyring in a separate file, so that it can be packaged up and just installed in one step by a package manager (or downloaded with fetch/curl/wget) as any other file. (The package manager handles preventing publisher A's special this-is-my-repository-keyring package from installing over publisher B's, in the normal way that it handles file conflicts between packages in general.) But it still adds it to the set of keys that is globally trusted for all repositories. The full mechanism that exists now uses separate, not globally trusted, keyring files in /usr/share/keyrings/.



          My instructions are already there. ☺ There are moves afoot to move Debian's own repositories to this mechanism, so that they no longer use globally trusted keys either. You might want to have a word with those "most projects" that you found. After all, they are currently instructing you to hand over global access to APT on your machine to them.



          Further reading



          • Daniel Kahn Gillmor (2017-05-02). Please ship release-specific keys separately outside of /etc/apt/trusted.gpg.d/. Debian bug #861695.

          • Daniel Kahn Gillmor (2017-07-27). debian sources.list entries should have signed-by options pointing to specific keys. Debian bug #877012.


          • "Sources.list entry". Instructions to connect to a third-party repository. Debian wiki. 2018.

          • Why isn't it a security risk to add to sources.list?

          • Debian 9, APT, and "GPG error: ... InRelease: The following signatures were invalid:"






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 7 at 19:22









          Wildcard

          22.1k858154




          22.1k858154










          answered Aug 17 at 9:18









          JdeBP

          29.4k460136




          29.4k460136






















              up vote
              1
              down vote













              apt-key del takes the keyid, which is a meaningless hash of the key.



              It is simpler if you can uninstall keys using a meaningful name... like a filename.



              As JdeBP says, this works nicely with trusted key files that are installed as part of a debian package. I think it can also be nicer when you've manually installed a key file.



              In the new mechanism which is currently in "initial testing", this is further simplified. You only have to remove/disable one thing: the repository (in sources.list / sources.list.d). That will automatically stop allowing the key configured for that repo (unless it was also used by another repo).



              I don't know how to take advantage of the new mechanism for security. I just assume that I need to trust someone if I use their package. The package install process is still running as root :-).






              share|improve this answer


























                up vote
                1
                down vote













                apt-key del takes the keyid, which is a meaningless hash of the key.



                It is simpler if you can uninstall keys using a meaningful name... like a filename.



                As JdeBP says, this works nicely with trusted key files that are installed as part of a debian package. I think it can also be nicer when you've manually installed a key file.



                In the new mechanism which is currently in "initial testing", this is further simplified. You only have to remove/disable one thing: the repository (in sources.list / sources.list.d). That will automatically stop allowing the key configured for that repo (unless it was also used by another repo).



                I don't know how to take advantage of the new mechanism for security. I just assume that I need to trust someone if I use their package. The package install process is still running as root :-).






                share|improve this answer
























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  apt-key del takes the keyid, which is a meaningless hash of the key.



                  It is simpler if you can uninstall keys using a meaningful name... like a filename.



                  As JdeBP says, this works nicely with trusted key files that are installed as part of a debian package. I think it can also be nicer when you've manually installed a key file.



                  In the new mechanism which is currently in "initial testing", this is further simplified. You only have to remove/disable one thing: the repository (in sources.list / sources.list.d). That will automatically stop allowing the key configured for that repo (unless it was also used by another repo).



                  I don't know how to take advantage of the new mechanism for security. I just assume that I need to trust someone if I use their package. The package install process is still running as root :-).






                  share|improve this answer














                  apt-key del takes the keyid, which is a meaningless hash of the key.



                  It is simpler if you can uninstall keys using a meaningful name... like a filename.



                  As JdeBP says, this works nicely with trusted key files that are installed as part of a debian package. I think it can also be nicer when you've manually installed a key file.



                  In the new mechanism which is currently in "initial testing", this is further simplified. You only have to remove/disable one thing: the repository (in sources.list / sources.list.d). That will automatically stop allowing the key configured for that repo (unless it was also used by another repo).



                  I don't know how to take advantage of the new mechanism for security. I just assume that I need to trust someone if I use their package. The package install process is still running as root :-).







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 17 at 12:55

























                  answered Aug 17 at 12:30









                  sourcejedi

                  20.1k42884




                  20.1k42884



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463072%2fwhy-does-the-apt-key-man-page-advise-against-using-its-add-command%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?