How to allow a command to be executed for a particular user without password with sudoers file?












2















Can anyone please explain the exact work of these in /etc/sudoers ? (I've done some research, so please don't share any links)



I want to add myself (member of sudo) to execute a command without password.But it's again asking for password.



# User

root ALL=(ALL:ALL) ALL

myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*

# Groups

%sudo ALL=(ALL:ALL) ALL









share|improve this question





























    2















    Can anyone please explain the exact work of these in /etc/sudoers ? (I've done some research, so please don't share any links)



    I want to add myself (member of sudo) to execute a command without password.But it's again asking for password.



    # User

    root ALL=(ALL:ALL) ALL

    myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*

    # Groups

    %sudo ALL=(ALL:ALL) ALL









    share|improve this question



























      2












      2








      2


      1






      Can anyone please explain the exact work of these in /etc/sudoers ? (I've done some research, so please don't share any links)



      I want to add myself (member of sudo) to execute a command without password.But it's again asking for password.



      # User

      root ALL=(ALL:ALL) ALL

      myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*

      # Groups

      %sudo ALL=(ALL:ALL) ALL









      share|improve this question
















      Can anyone please explain the exact work of these in /etc/sudoers ? (I've done some research, so please don't share any links)



      I want to add myself (member of sudo) to execute a command without password.But it's again asking for password.



      # User

      root ALL=(ALL:ALL) ALL

      myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*

      # Groups

      %sudo ALL=(ALL:ALL) ALL






      permissions sudo visudo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 11 at 8:32









      Sergiy Kolodyazhnyy

      71k9147312




      71k9147312










      asked Jan 11 at 8:27









      Purnendu NathPurnendu Nath

      1381213




      1381213






















          4 Answers
          4






          active

          oldest

          votes


















          3














          I pretty much stole it from here: Is it possible to give sudo access to only a particular command?



          sudo visudo -f /etc/sudoers.d/Username


          And add that to the file:



          Username ALL = NOPASSWD: /usr/bin/apt* update
          Username ALL = NOPASSWD: /usr/bin/apt* install


          Don't know how to make this a one-liner, though. Hope that helps.






          share|improve this answer
























          • It can be made a one-liner with a command alias Cmnd_Alias, see the sudoers snippet in this loosely related answer, section Another approach.

            – PerlDuck
            Jan 11 at 10:48





















          1














          This is my first post on askubuntu but i am pretty sure you could do it like that create a file with your username in /etc/sudoers.d/ with:



          username ALL = NOPASSWD: ALL





          share|improve this answer
























          • NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient.

            – Sergiy Kolodyazhnyy
            Jan 11 at 8:47



















          1














          The order of configuration lines has significance in the sudoers file: the last applicable line wins.



          If user myself is a member of the sudo group, all commands issued by that user will always match the %sudo ALL=(ALL:ALL) ALL line. As it has no NOPASSWD: flag, password will be asked.



          The fix is to arrange the /etc/sudoers configuration lines in the order of increasing specificity:



          # Groups 

          %sudo ALL=(ALL:ALL) ALL

          # User

          root ALL=(ALL:ALL) ALL

          myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*


          When this order is used, if user myself runs sudo apt update, it will match the last line with the NOPASSWD: flag.






          share|improve this answer































            0














            You can simple add the next line to your sudoers file:



            username ALL=NOPASSWD: command1, command2, command3 [...]


            Remember to separated with commas all commands you want to be executed by user with out password promp.






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1108782%2fhow-to-allow-a-command-to-be-executed-for-a-particular-user-without-password-wit%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              I pretty much stole it from here: Is it possible to give sudo access to only a particular command?



              sudo visudo -f /etc/sudoers.d/Username


              And add that to the file:



              Username ALL = NOPASSWD: /usr/bin/apt* update
              Username ALL = NOPASSWD: /usr/bin/apt* install


              Don't know how to make this a one-liner, though. Hope that helps.






              share|improve this answer
























              • It can be made a one-liner with a command alias Cmnd_Alias, see the sudoers snippet in this loosely related answer, section Another approach.

                – PerlDuck
                Jan 11 at 10:48


















              3














              I pretty much stole it from here: Is it possible to give sudo access to only a particular command?



              sudo visudo -f /etc/sudoers.d/Username


              And add that to the file:



              Username ALL = NOPASSWD: /usr/bin/apt* update
              Username ALL = NOPASSWD: /usr/bin/apt* install


              Don't know how to make this a one-liner, though. Hope that helps.






              share|improve this answer
























              • It can be made a one-liner with a command alias Cmnd_Alias, see the sudoers snippet in this loosely related answer, section Another approach.

                – PerlDuck
                Jan 11 at 10:48
















              3












              3








              3







              I pretty much stole it from here: Is it possible to give sudo access to only a particular command?



              sudo visudo -f /etc/sudoers.d/Username


              And add that to the file:



              Username ALL = NOPASSWD: /usr/bin/apt* update
              Username ALL = NOPASSWD: /usr/bin/apt* install


              Don't know how to make this a one-liner, though. Hope that helps.






              share|improve this answer













              I pretty much stole it from here: Is it possible to give sudo access to only a particular command?



              sudo visudo -f /etc/sudoers.d/Username


              And add that to the file:



              Username ALL = NOPASSWD: /usr/bin/apt* update
              Username ALL = NOPASSWD: /usr/bin/apt* install


              Don't know how to make this a one-liner, though. Hope that helps.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 11 at 8:59









              Patient32BitPatient32Bit

              616




              616













              • It can be made a one-liner with a command alias Cmnd_Alias, see the sudoers snippet in this loosely related answer, section Another approach.

                – PerlDuck
                Jan 11 at 10:48





















              • It can be made a one-liner with a command alias Cmnd_Alias, see the sudoers snippet in this loosely related answer, section Another approach.

                – PerlDuck
                Jan 11 at 10:48



















              It can be made a one-liner with a command alias Cmnd_Alias, see the sudoers snippet in this loosely related answer, section Another approach.

              – PerlDuck
              Jan 11 at 10:48







              It can be made a one-liner with a command alias Cmnd_Alias, see the sudoers snippet in this loosely related answer, section Another approach.

              – PerlDuck
              Jan 11 at 10:48















              1














              This is my first post on askubuntu but i am pretty sure you could do it like that create a file with your username in /etc/sudoers.d/ with:



              username ALL = NOPASSWD: ALL





              share|improve this answer
























              • NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient.

                – Sergiy Kolodyazhnyy
                Jan 11 at 8:47
















              1














              This is my first post on askubuntu but i am pretty sure you could do it like that create a file with your username in /etc/sudoers.d/ with:



              username ALL = NOPASSWD: ALL





              share|improve this answer
























              • NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient.

                – Sergiy Kolodyazhnyy
                Jan 11 at 8:47














              1












              1








              1







              This is my first post on askubuntu but i am pretty sure you could do it like that create a file with your username in /etc/sudoers.d/ with:



              username ALL = NOPASSWD: ALL





              share|improve this answer













              This is my first post on askubuntu but i am pretty sure you could do it like that create a file with your username in /etc/sudoers.d/ with:



              username ALL = NOPASSWD: ALL






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 11 at 8:40







              user912780




















              • NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient.

                – Sergiy Kolodyazhnyy
                Jan 11 at 8:47



















              • NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient.

                – Sergiy Kolodyazhnyy
                Jan 11 at 8:47

















              NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient.

              – Sergiy Kolodyazhnyy
              Jan 11 at 8:47





              NOPASSWD: ALL is aimed at making all commands run without passwords. So ALL should be replaced by /bin/apt update. But overall you're right, I think. This syntax should be sufficient.

              – Sergiy Kolodyazhnyy
              Jan 11 at 8:47











              1














              The order of configuration lines has significance in the sudoers file: the last applicable line wins.



              If user myself is a member of the sudo group, all commands issued by that user will always match the %sudo ALL=(ALL:ALL) ALL line. As it has no NOPASSWD: flag, password will be asked.



              The fix is to arrange the /etc/sudoers configuration lines in the order of increasing specificity:



              # Groups 

              %sudo ALL=(ALL:ALL) ALL

              # User

              root ALL=(ALL:ALL) ALL

              myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*


              When this order is used, if user myself runs sudo apt update, it will match the last line with the NOPASSWD: flag.






              share|improve this answer




























                1














                The order of configuration lines has significance in the sudoers file: the last applicable line wins.



                If user myself is a member of the sudo group, all commands issued by that user will always match the %sudo ALL=(ALL:ALL) ALL line. As it has no NOPASSWD: flag, password will be asked.



                The fix is to arrange the /etc/sudoers configuration lines in the order of increasing specificity:



                # Groups 

                %sudo ALL=(ALL:ALL) ALL

                # User

                root ALL=(ALL:ALL) ALL

                myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*


                When this order is used, if user myself runs sudo apt update, it will match the last line with the NOPASSWD: flag.






                share|improve this answer


























                  1












                  1








                  1







                  The order of configuration lines has significance in the sudoers file: the last applicable line wins.



                  If user myself is a member of the sudo group, all commands issued by that user will always match the %sudo ALL=(ALL:ALL) ALL line. As it has no NOPASSWD: flag, password will be asked.



                  The fix is to arrange the /etc/sudoers configuration lines in the order of increasing specificity:



                  # Groups 

                  %sudo ALL=(ALL:ALL) ALL

                  # User

                  root ALL=(ALL:ALL) ALL

                  myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*


                  When this order is used, if user myself runs sudo apt update, it will match the last line with the NOPASSWD: flag.






                  share|improve this answer













                  The order of configuration lines has significance in the sudoers file: the last applicable line wins.



                  If user myself is a member of the sudo group, all commands issued by that user will always match the %sudo ALL=(ALL:ALL) ALL line. As it has no NOPASSWD: flag, password will be asked.



                  The fix is to arrange the /etc/sudoers configuration lines in the order of increasing specificity:



                  # Groups 

                  %sudo ALL=(ALL:ALL) ALL

                  # User

                  root ALL=(ALL:ALL) ALL

                  myself ALL=(ALL:ALL) NOPASSWD:/bin/apt update, PASSWD:/bin/apt install*


                  When this order is used, if user myself runs sudo apt update, it will match the last line with the NOPASSWD: flag.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 11 at 13:23









                  telcoMtelcoM

                  1544




                  1544























                      0














                      You can simple add the next line to your sudoers file:



                      username ALL=NOPASSWD: command1, command2, command3 [...]


                      Remember to separated with commas all commands you want to be executed by user with out password promp.






                      share|improve this answer




























                        0














                        You can simple add the next line to your sudoers file:



                        username ALL=NOPASSWD: command1, command2, command3 [...]


                        Remember to separated with commas all commands you want to be executed by user with out password promp.






                        share|improve this answer


























                          0












                          0








                          0







                          You can simple add the next line to your sudoers file:



                          username ALL=NOPASSWD: command1, command2, command3 [...]


                          Remember to separated with commas all commands you want to be executed by user with out password promp.






                          share|improve this answer













                          You can simple add the next line to your sudoers file:



                          username ALL=NOPASSWD: command1, command2, command3 [...]


                          Remember to separated with commas all commands you want to be executed by user with out password promp.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 11 at 10:02









                          WilliWonkaWilliWonka

                          485




                          485






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1108782%2fhow-to-allow-a-command-to-be-executed-for-a-particular-user-without-password-wit%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to change which sound is reproduced for terminal bell?

                              Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                              Can I use Tabulator js library in my java Spring + Thymeleaf project?