How to run a specific program as root without a password prompt? The Next CEO of Stack OverflowI'm not getting privileges, edited /etc/sudoerssudo: password prompted even when NOPASSWD is setHow do you get NOPASSWD sudo option to work in Fedora 15?Sudo with NOPASSWD and service restartNo password to run command as root for fixed command?How can I add sudo permission for copying?How to make sudo accept password automatically without prompting for it?Is it possible to write a script that run su or sudo command without typing password?Allow all commands via sudo but nopasswd for specific commandsSudo specific command with no passwordFinding root passwordHow can I run reboot as a normal user without needing to enter a password?How does sudo really work?Use rtcwake without entering a passwordWhy do I still need to run shutdown as sudo after this?Why does sudo not prompt for a password again after “command not found”?Can a program run by a NOPASSWD sudoer use sudo to gain root access?Checking sudoers without root?run certain program without sudo but with password promptHow to run ip netns exec without password?

Mathematica command that allows it to read my intentions

Find a path from s to t using as few red nodes as possible

Compensation for working overtime on Saturdays

Is this a new Fibonacci Identity?

Free fall ellipse or parabola?

Shortening a title without changing its meaning

Can a PhD from a non-TU9 German university become a professor in a TU9 university?

How seriously should I take size and weight limits of hand luggage?

How to find if SQL server backup is encrypted with TDE without restoring the backup

Calculating discount not working

Prodigo = pro + ago?

Is a distribution that is normal, but highly skewed, considered Gaussian?

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

Gödel's incompleteness theorems - what are the religious implications?

Can Sri Krishna be called 'a person'?

How can I separate the number from the unit in argument?

How can I prove that a state of equilibrium is unstable?

What difference does it make matching a word with/without a trailing whitespace?

Could a dragon use its wings to swim?

pgfplots: How to draw a tangent graph below two others?

MT "will strike" & LXX "will watch carefully" (Gen 3:15)?

Why did the Drakh emissary look so blurred in S04:E11 "Lines of Communication"?

How to implement Comparable so it is consistent with identity-equality

Creating a script with console commands



How to run a specific program as root without a password prompt?



The Next CEO of Stack OverflowI'm not getting privileges, edited /etc/sudoerssudo: password prompted even when NOPASSWD is setHow do you get NOPASSWD sudo option to work in Fedora 15?Sudo with NOPASSWD and service restartNo password to run command as root for fixed command?How can I add sudo permission for copying?How to make sudo accept password automatically without prompting for it?Is it possible to write a script that run su or sudo command without typing password?Allow all commands via sudo but nopasswd for specific commandsSudo specific command with no passwordFinding root passwordHow can I run reboot as a normal user without needing to enter a password?How does sudo really work?Use rtcwake without entering a passwordWhy do I still need to run shutdown as sudo after this?Why does sudo not prompt for a password again after “command not found”?Can a program run by a NOPASSWD sudoer use sudo to gain root access?Checking sudoers without root?run certain program without sudo but with password promptHow to run ip netns exec without password?










148















I need to run something as sudo without a password, so I used visudo and added this to my sudoers file:



MYUSERNAME ALL = NOPASSWD: /path/to/my/program


Then I tried it out:



$ sudo /path/to/my/program
[sudo] password for MYUSERNAME:


Why does it ask for a password? How can I run/use commands as root with a non-root user, without asking for a password?










share|improve this question




























    148















    I need to run something as sudo without a password, so I used visudo and added this to my sudoers file:



    MYUSERNAME ALL = NOPASSWD: /path/to/my/program


    Then I tried it out:



    $ sudo /path/to/my/program
    [sudo] password for MYUSERNAME:


    Why does it ask for a password? How can I run/use commands as root with a non-root user, without asking for a password?










    share|improve this question


























      148












      148








      148


      39






      I need to run something as sudo without a password, so I used visudo and added this to my sudoers file:



      MYUSERNAME ALL = NOPASSWD: /path/to/my/program


      Then I tried it out:



      $ sudo /path/to/my/program
      [sudo] password for MYUSERNAME:


      Why does it ask for a password? How can I run/use commands as root with a non-root user, without asking for a password?










      share|improve this question
















      I need to run something as sudo without a password, so I used visudo and added this to my sudoers file:



      MYUSERNAME ALL = NOPASSWD: /path/to/my/program


      Then I tried it out:



      $ sudo /path/to/my/program
      [sudo] password for MYUSERNAME:


      Why does it ask for a password? How can I run/use commands as root with a non-root user, without asking for a password?







      sudo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 17 '11 at 0:31









      Gilles

      545k12911071623




      545k12911071623










      asked Aug 16 '11 at 10:29









      LanceBaynesLanceBaynes

      10.8k77200327




      10.8k77200327




















          13 Answers
          13






          active

          oldest

          votes


















          80














          You have another entry in the sudoers file which also matches your user. The NOPASSWD rule needs to be after that one in order for it to take precedence.



          Having done that, sudo will prompt for a password normally for all commands except /path/to/my/program, which it will always let you run without asking for your password.






          share|improve this answer




















          • 5





            would this still work if the /path/to/my/program was a python script?

            – sadmicrowave
            Mar 3 '14 at 20:29











          • Can the program instead be an alias, set for bash (ie in .bashrc)? Or even a shell script inside /usr/local/sbin? To try out.

            – Nikos Alexandris
            Aug 5 '16 at 16:11












          • Nikos - no it cannot be an alias. It must point to a real path.

            – Paul Hedderly
            Jan 31 at 10:14


















          116














          If there are multiple matching entries in /etc/sudoers, sudo uses the last one. Therefore, if you can execute any command with a password prompt, and you want to be able to execute a particular command without a password prompt, you need the exception last.



          myusername ALL = (ALL) ALL
          myusername ALL = (root) NOPASSWD: /path/to/my/program


          Note the use of (root), to allow the program to be run as root but not as other users. (Don't give more permissions than the minimum required unless you've thought out the implications.)



          Note for readers who aren't running Ubuntu or who have changed the default sudo configuration (Ubuntu's sudo is ok by default): Running shell scripts with elevated privileges is risky, you need to start from a clean environment (once the shell has started, it's too late (see Allow setuid on shell scripts), so you need sudo to take care of that). Make sure that you have Defaults env_reset in /etc/sudoers or that this option is the compile-time default (sudo sudo -V | grep env should include Reset the environment to a default set of variables).






          share|improve this answer




















          • 2





            ex to go root from jhon with sudo su an no pass -----> john ALL=(ALL) NOPASSWD: /bin/su

            – bortunac
            Jul 13 '14 at 14:05







          • 4





            @adrian If you want to allow arbitrary commands as root, make that john ALL=(ALL) NOPASSWD: all. There's no point in going via su.

            – Gilles
            Jul 13 '14 at 14:08











          • Question: should I alter the permissions of my shell script so that it can get modified and read by root user only, for security? I'm thinking about an attacker modifying the script, which has all the permissions granted without the need of a password, so that it does what he/she wants. Obviously, the attacker can't even read sudoers file to know which scripts have this privilege, but can still try with all my custom scripts once he/she finds the folder in which they are stored in hope some are allowed, or something like that.

            – Jeffrey Lebowski
            Oct 10 '17 at 18:13







          • 1





            @JeffreyLebowski If you have a sudo rule that runs the script (directly or indirectly) then it's vital that only root (or people who have root privileges anyway) can write to the script file, and to the directory containing the script file, and to its parent directory and so on. It doesn't matter that anyone can read the script file (unless it contains a password or something, but that's a bad idea, if there's a password it should be in its own file, otherwise there's too much risk of accidentally leaking it e.g. by copy-pasting that section of the code in a question on this site).

            – Gilles
            Oct 10 '17 at 18:51






          • 1





            @alper No. Very few things require rebooting. After changing sudoers, you don't need to do anything special: sudo checks it each time.

            – Gilles
            Mar 18 at 19:02


















          21















          WARNING: This answer has been deemed insecure. See comments below



          Complete Solution: The following steps will help you achieve the desired output:




          1. Create a new script file (replace create_dir.sh with your desired script name):



            vim ~/create_dir.sh


            The script will be created in the user’s home directory




          2. Add some commands that only a root or sudo user can execute like creating a folder at the root directory level:



            mkdir /abc


            Note: Don’t add sudo to these commands. Save and exit (using :wq!)




          3. Assign execute permissions to it using:



            sudo chmod u+x create_dir.sh



          4. Make changes so that this script doesn’t require a password.




            1. Open the sudoers file:



              sudo visudo -f /etc/sudoers



            2. Add the following line at the end:



              ahmad ALL=(root) NOPASSWD: /home/ahmad/create_dir.sh


              Replace ahmad with whatever your username is. Also make sure this is the last line. Save and exit.





          5. Now when running the command add sudo before it like:



            sudo ./create_dir.sh


            This will run the commands inside the script file without asking for a password.



          Follow the easy steps mentioned here http://step4wd.com/2013/09/14/run-root-commands-in-linux-ubuntu-without-password/






          share|improve this answer

























          • It would be better if you provided the relevant steps here and used the link as a backup for more detailed information. That way your answer retains possible value even if that link would not be valid anymore.

            – Anthon
            Sep 14 '13 at 5:37






          • 14





            This advice is insecure. The sudo part of sudo chmod u+x create_dir.sh is unnecessary as the user has (presumably) ownership over his/her home dir. Since the user can write to create_dir.sh, you have effectively given a free root shell to that user.

            – Lekensteyn
            Jul 19 '14 at 8:36











          • @Lekensteyn Which means also to any program running as the user. Might as well just allow the user to run anything with sudo without a password.

            – pydsigner
            May 23 '16 at 1:41






          • 2





            Am I missing something? I believe that the entire chmod is unnecessary, since you’re relying on sudo to elevate your privileges.

            – G-Man
            Jun 13 '18 at 14:57


















          8














          I think your syntax is wrong. At least I use the following which works for me:



          myusername ALL=(ALL) NOPASSWD: /path/to/executable





          share|improve this answer


















          • 6





            The (ALL) part is optional, leaving it out has exactly the same effect. Having (root) would be better though, but its absence doesn't explain the problem.

            – Gilles
            May 12 '11 at 11:39











          • +1 for sudo for this command and nothing else! No reason to break the entire system...

            – Johan
            May 12 '11 at 11:40






          • 3





            @Johan: That was already in the question.

            – Gilles
            May 12 '11 at 12:13


















          4














          Verify that sudo is not aliased. Run like this



          /usr/bin/sudo /path/to/my/program


          For example a shell alias like this one:



          alias sudo="sudo env PATH=$PATH"


          may cause this behaviour.






          share|improve this answer

























          • You are right, my comment was out of order here, sorry for that. Nevertheless I'm intrigued - how do you expect aliasing to change the processing of sudoers by sudo. Or are you talking about redirecting sudo to something that always prints this error message to scoop passwords? That is unlikely the case here...

            – peterph
            Jul 19 '14 at 8:18






          • 2





            I was having the same problem as the OP. It turned out to be caused by having alias sudo="sudo env PATH=$PATH" in my ~/.bashrc. Rather than just solving it for myself and blindly just going about my business, I submitted my answer as a possible solution for anyone else that comes along this thread.

            – Sepero
            Jul 19 '14 at 22:50












          • That's fine, but when it is not obvious (which in this case isn't at least to some people) it is good to put an explanation into the answer to provide some context and prevent people from blindly using magic incantations. +2 (-(-1) + +1). :)

            – peterph
            Jul 24 '14 at 22:45


















          4














          In some distros, Manjaro in my case, there is a file that overrides the /etc/sudoers file



          sudo cat /etc/sudoers.d/10-installer


          • the ONLY way to see it is under root privilegies, you cannot list this directory without it.

          There you will find something like this:



          youruser ALL=(ALL)


          You can delete that file, and will use cfg in /etc/sudoers file




          /etc/sudoers:



          In the sudoers file you must put something like:



          %group ALL=(ALL) NOPASSWD: ALL


          or



          youruser ALL=(ALL) NOPASSWD: ALL


          or



          youruser ALL=(ALL) NOPASSWD: /path/to/executable


          I hope this helps somebody :).






          share|improve this answer






























            2














            When you execute your script you need to run it as sudo /path/to/my/script.



            Edit: Based on your comment to another answer, you want to run this from an icon. You will need to create a .desktop file that executes your program with sudo, just like on the terminal.



            You could also consider using gtk-sudo for a visual password prompt.



            You should probably consider the idea that you shouldn't be running things as root and that changing the system farther down the road so that you don't need root permissions at all would be a better way to go.






            share|improve this answer




















            • 6





              Do not make shell scripts setuid. See Allow setuid on shell scripts.

              – Gilles
              May 12 '11 at 11:38











            • I considered not even mentioning it because it's such a bad option. I just deleted it because I'm worried this asker might use the advice even with the warning that it was bad advice!

              – Caleb
              May 12 '11 at 11:41


















            2














            This solved the issue for me (also tried some of the other answers, that might have helped):



            The script I was calling was in /usr/bin, a directory that I don't have write permissions to (though I can usually read any files there). The script was chmodded +x (executable permisison), but it still didn't work. Moving this file to a path in my home directory, instead of /usr/bin, I was finally able to call it with sudo without entering a password.



            Also something I doubted about (clarifying for future readers): You need to run your script as sudo. Type sudo when calling the script. Don't use sudo for the command inside your script that actually needs root (changing keyboard backlight in my case). Perhaps that also works, but you don't need to, and it seems like a better solution not to.






            share|improve this answer

























            • The second paragraph had the answer to my problem

              – M. Ahmad Zafar
              Sep 13 '13 at 8:02











            • @MuhammadAhmadZafar Glad it helped!

              – Luc
              Sep 13 '13 at 10:53






            • 3





              Actually using sudo inside of a script is perfectly fine provided you have the appropriate rights (set in sudoers) to run the command in question without a password. It makes things a bit more secure.

              – peterph
              Jul 19 '14 at 8:21











            • could really use this answer re-written as a step-by-step 'this is how you do it' rather than as a dialogue with the other answers

              – Walrus the Cat
              Nov 28 '17 at 22:31











            • @WalrustheCat Good point. Re-reading my answer, I think I might have been confused a little myself. Right now though, I don't remember what the exact situation was so I can't really do a better writeup. If you figure it out, perhaps a combination of several answers, by all means submit a new answer!

              – Luc
              Nov 29 '17 at 7:24


















            2














            If you want to avoid having to use sudo nor have to change the sudoers config file, you can use:



            sudo chown root:root path/to/command/COMMAND_NAME
            sudo chmod 4775 path/to/command/COMMAND_NAME


            This will make the command run as root without the need of sudo.






            share|improve this answer

























            • Wow, I never heard of this solution before, mind boggling

              – somethingSomething
              Nov 10 '18 at 14:18


















            1














            Another possibility might be to install, configure, then use the super command to run your script as



            super /path/to/your/script



            If you want to run some binary executable (e.g. that you have compiled into ELF binary from some C source code) -which is not a script- as root, you might consider making it setuid (and actually /bin/login, /usr/bin/sudo and /bin/su and super are all using that technique). However, be very careful, you could open a huge security hole.



            Concretely, your program should be paranoically coded (so check all arguments and the environment and outside conditions before "acting", assuming a potentially hostile user), then you could use seteuid(2) and friends (see also setreuid(2)) carefully (see also capabilities(7) & credentials(7) & execve(2)...)



            You'll use chmod u+s (read chmod(1)) when installing such a binary.



            But be very careful.



            Read many things about setuid, including Advanced Linux Programming, before coding such a thing.



            Notice that a script, or any shebang-ed thing, cannot be setuid. But you could code (in C) a small setuid-binary wrapping it.






            share|improve this answer
































              0














              Ideally if you are customizing what commands can be run via sudo you should be making these changes in a separate file under /etc/sudoers.d/ instead of editing the sudoers file directly. You should also always use visudo to edit the file(s). You should NEVER grant NOPASSWD on ALL commands.



              Example:
              sudo visudo -f /etc/sudoers.d/mynotriskycommand



              Insert your line granting permission:
              myuser ALL= NOPASSWD: /path/to/your/program



              Then save and exit and visudo will warn you if you have any syntax errors.



              You can run sudo -l to see the permissions that your user has been granted, if any of the user specific NOPASSWD commands appear BEFORE any %groupyouarein ALL=(ALL) ALL command in the output you will be prompted for your password.



              If you find yourself creating lots of these sudoers.d files then perhaps you will want to create them named per user so they are easier to visualize. Keep in mind that the ordering of the FILE NAMES and of the RULES within the file is very important, the LAST one loaded wins, whether it is MORE or LESS permissive than the previous entries.




              You can control the file name ordering by using a prefix of 00-99 or aa/bb/cc, though also keep in mind that if you have ANY files that don't have numeric prefix, they will load after the numbered files, overriding the settings. This is because depending on your language settings the "lexical sorting" the shell uses sorts numbers first and then may interleave upper and lowercase when sorting in "ascending" order.




              Try running printf '%sn' 0..99,A-Z,a-z | sort and printf '%sn' 0..99,A-Z,a-z | LANG=C sort to see whether your current language prints AaBbCc etc or ABC then abc to determine what the best "last" letter prefix to use would be.






              share|improve this answer






























                0














                To allow any user to execute program as sudo without asking password you can add following line



                %sudo ALL=(root) NOPASSWD: /path/to/your/program



                in /etc/sudoers



                Note that %sudo make it.






                share|improve this answer























                • While that's one way to accomplish a sudo rule, it doesn't answer the question about why setting the NOPASSWD flag on this rule still resulted in a password prompt. See the accepted answer for an idea why it happened.

                  – Jeff Schaller
                  Mar 2 at 17:19











                • Thank you for pointing out. @JeffSchaller

                  – ultimatex
                  Mar 2 at 17:39


















                0














                The following is for the case where you want to run a command without password only if it has a specific set of options, where a part of the options is variable. AFAIK it is not possible to use variables or value ranges in sudoers declarations, i.e. you can allow access explicitly to command option1 but not command option2 using:



                user_name ALL=(root) /usr/bin/command option1



                but if the structure is command option1 value1, where value1 can vary, you would need to have explicit sudoers lines for each possible value of value1. Shell script provides a way around it.



                This answer was inspired by M. Ahmad Zafar's answer and fixes the security issue there.



                1. Create a shell script where you call the command without sudo.

                2. Save the script in a root-privileged folder (e.g. /usr/local/bin/), make the file root-owned (e.g. chown root:wheel /usr/local/bin/script_name) with no write access for others (e.g. chmod 755 /usr/local/bin/script_name).


                3. Add the exception to sudoers using visudo:



                  user_name ALL=(root) NOPASSWD: /usr/local/bin/script_name.



                4. Run your script sudo script_name.


                For example, I want to change display sleep timeout on macOS. This is done using:



                sudo pmset displaysleep time_in_minutes



                I consider changing the sleep timeout an innocent action that doesn't justify the hassle of password typing, but pmset can do many things and I'd like to keep these other things behind the sudo password.



                So I have the following script at /usr/local/bin/ds:



                #!/bin/bash
                if [ $# -eq 0 ]; then
                echo 'To set displaysleep time, run "sudo ds [sleep_time_in_minutes]"'
                else
                if [[ $1 =~ ^([0-9]|[1-9][0-9]|1[0-7][0-9]|180)$ ]]; then
                pmset displaysleep $1
                else
                echo 'Time must be 0..180, where 0 = never, 1..180 = number of minutes'
                fi
                fi


                At the end of sudoers file I have the following line:



                user_name ALL=(root) NOPASSWD: /usr/local/bin/ds



                To set the timeout at 3 minutes, I run my script from the ordinary user account user_name:



                sudo ds 3



                PS Most of my script is input validation, which is not mandatory, so the following would also work:



                #!/bin/bash
                pmset displaysleep $1





                share|improve this answer








                New contributor




                Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.




















                  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',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  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%2funix.stackexchange.com%2fquestions%2f18830%2fhow-to-run-a-specific-program-as-root-without-a-password-prompt%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  13 Answers
                  13






                  active

                  oldest

                  votes








                  13 Answers
                  13






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  80














                  You have another entry in the sudoers file which also matches your user. The NOPASSWD rule needs to be after that one in order for it to take precedence.



                  Having done that, sudo will prompt for a password normally for all commands except /path/to/my/program, which it will always let you run without asking for your password.






                  share|improve this answer




















                  • 5





                    would this still work if the /path/to/my/program was a python script?

                    – sadmicrowave
                    Mar 3 '14 at 20:29











                  • Can the program instead be an alias, set for bash (ie in .bashrc)? Or even a shell script inside /usr/local/sbin? To try out.

                    – Nikos Alexandris
                    Aug 5 '16 at 16:11












                  • Nikos - no it cannot be an alias. It must point to a real path.

                    – Paul Hedderly
                    Jan 31 at 10:14















                  80














                  You have another entry in the sudoers file which also matches your user. The NOPASSWD rule needs to be after that one in order for it to take precedence.



                  Having done that, sudo will prompt for a password normally for all commands except /path/to/my/program, which it will always let you run without asking for your password.






                  share|improve this answer




















                  • 5





                    would this still work if the /path/to/my/program was a python script?

                    – sadmicrowave
                    Mar 3 '14 at 20:29











                  • Can the program instead be an alias, set for bash (ie in .bashrc)? Or even a shell script inside /usr/local/sbin? To try out.

                    – Nikos Alexandris
                    Aug 5 '16 at 16:11












                  • Nikos - no it cannot be an alias. It must point to a real path.

                    – Paul Hedderly
                    Jan 31 at 10:14













                  80












                  80








                  80







                  You have another entry in the sudoers file which also matches your user. The NOPASSWD rule needs to be after that one in order for it to take precedence.



                  Having done that, sudo will prompt for a password normally for all commands except /path/to/my/program, which it will always let you run without asking for your password.






                  share|improve this answer















                  You have another entry in the sudoers file which also matches your user. The NOPASSWD rule needs to be after that one in order for it to take precedence.



                  Having done that, sudo will prompt for a password normally for all commands except /path/to/my/program, which it will always let you run without asking for your password.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 24 '17 at 11:09









                  αғsнιη

                  17.1k103069




                  17.1k103069










                  answered Aug 16 '11 at 11:32









                  Warren YoungWarren Young

                  56k11143148




                  56k11143148







                  • 5





                    would this still work if the /path/to/my/program was a python script?

                    – sadmicrowave
                    Mar 3 '14 at 20:29











                  • Can the program instead be an alias, set for bash (ie in .bashrc)? Or even a shell script inside /usr/local/sbin? To try out.

                    – Nikos Alexandris
                    Aug 5 '16 at 16:11












                  • Nikos - no it cannot be an alias. It must point to a real path.

                    – Paul Hedderly
                    Jan 31 at 10:14












                  • 5





                    would this still work if the /path/to/my/program was a python script?

                    – sadmicrowave
                    Mar 3 '14 at 20:29











                  • Can the program instead be an alias, set for bash (ie in .bashrc)? Or even a shell script inside /usr/local/sbin? To try out.

                    – Nikos Alexandris
                    Aug 5 '16 at 16:11












                  • Nikos - no it cannot be an alias. It must point to a real path.

                    – Paul Hedderly
                    Jan 31 at 10:14







                  5




                  5





                  would this still work if the /path/to/my/program was a python script?

                  – sadmicrowave
                  Mar 3 '14 at 20:29





                  would this still work if the /path/to/my/program was a python script?

                  – sadmicrowave
                  Mar 3 '14 at 20:29













                  Can the program instead be an alias, set for bash (ie in .bashrc)? Or even a shell script inside /usr/local/sbin? To try out.

                  – Nikos Alexandris
                  Aug 5 '16 at 16:11






                  Can the program instead be an alias, set for bash (ie in .bashrc)? Or even a shell script inside /usr/local/sbin? To try out.

                  – Nikos Alexandris
                  Aug 5 '16 at 16:11














                  Nikos - no it cannot be an alias. It must point to a real path.

                  – Paul Hedderly
                  Jan 31 at 10:14





                  Nikos - no it cannot be an alias. It must point to a real path.

                  – Paul Hedderly
                  Jan 31 at 10:14













                  116














                  If there are multiple matching entries in /etc/sudoers, sudo uses the last one. Therefore, if you can execute any command with a password prompt, and you want to be able to execute a particular command without a password prompt, you need the exception last.



                  myusername ALL = (ALL) ALL
                  myusername ALL = (root) NOPASSWD: /path/to/my/program


                  Note the use of (root), to allow the program to be run as root but not as other users. (Don't give more permissions than the minimum required unless you've thought out the implications.)



                  Note for readers who aren't running Ubuntu or who have changed the default sudo configuration (Ubuntu's sudo is ok by default): Running shell scripts with elevated privileges is risky, you need to start from a clean environment (once the shell has started, it's too late (see Allow setuid on shell scripts), so you need sudo to take care of that). Make sure that you have Defaults env_reset in /etc/sudoers or that this option is the compile-time default (sudo sudo -V | grep env should include Reset the environment to a default set of variables).






                  share|improve this answer




















                  • 2





                    ex to go root from jhon with sudo su an no pass -----> john ALL=(ALL) NOPASSWD: /bin/su

                    – bortunac
                    Jul 13 '14 at 14:05







                  • 4





                    @adrian If you want to allow arbitrary commands as root, make that john ALL=(ALL) NOPASSWD: all. There's no point in going via su.

                    – Gilles
                    Jul 13 '14 at 14:08











                  • Question: should I alter the permissions of my shell script so that it can get modified and read by root user only, for security? I'm thinking about an attacker modifying the script, which has all the permissions granted without the need of a password, so that it does what he/she wants. Obviously, the attacker can't even read sudoers file to know which scripts have this privilege, but can still try with all my custom scripts once he/she finds the folder in which they are stored in hope some are allowed, or something like that.

                    – Jeffrey Lebowski
                    Oct 10 '17 at 18:13







                  • 1





                    @JeffreyLebowski If you have a sudo rule that runs the script (directly or indirectly) then it's vital that only root (or people who have root privileges anyway) can write to the script file, and to the directory containing the script file, and to its parent directory and so on. It doesn't matter that anyone can read the script file (unless it contains a password or something, but that's a bad idea, if there's a password it should be in its own file, otherwise there's too much risk of accidentally leaking it e.g. by copy-pasting that section of the code in a question on this site).

                    – Gilles
                    Oct 10 '17 at 18:51






                  • 1





                    @alper No. Very few things require rebooting. After changing sudoers, you don't need to do anything special: sudo checks it each time.

                    – Gilles
                    Mar 18 at 19:02















                  116














                  If there are multiple matching entries in /etc/sudoers, sudo uses the last one. Therefore, if you can execute any command with a password prompt, and you want to be able to execute a particular command without a password prompt, you need the exception last.



                  myusername ALL = (ALL) ALL
                  myusername ALL = (root) NOPASSWD: /path/to/my/program


                  Note the use of (root), to allow the program to be run as root but not as other users. (Don't give more permissions than the minimum required unless you've thought out the implications.)



                  Note for readers who aren't running Ubuntu or who have changed the default sudo configuration (Ubuntu's sudo is ok by default): Running shell scripts with elevated privileges is risky, you need to start from a clean environment (once the shell has started, it's too late (see Allow setuid on shell scripts), so you need sudo to take care of that). Make sure that you have Defaults env_reset in /etc/sudoers or that this option is the compile-time default (sudo sudo -V | grep env should include Reset the environment to a default set of variables).






                  share|improve this answer




















                  • 2





                    ex to go root from jhon with sudo su an no pass -----> john ALL=(ALL) NOPASSWD: /bin/su

                    – bortunac
                    Jul 13 '14 at 14:05







                  • 4





                    @adrian If you want to allow arbitrary commands as root, make that john ALL=(ALL) NOPASSWD: all. There's no point in going via su.

                    – Gilles
                    Jul 13 '14 at 14:08











                  • Question: should I alter the permissions of my shell script so that it can get modified and read by root user only, for security? I'm thinking about an attacker modifying the script, which has all the permissions granted without the need of a password, so that it does what he/she wants. Obviously, the attacker can't even read sudoers file to know which scripts have this privilege, but can still try with all my custom scripts once he/she finds the folder in which they are stored in hope some are allowed, or something like that.

                    – Jeffrey Lebowski
                    Oct 10 '17 at 18:13







                  • 1





                    @JeffreyLebowski If you have a sudo rule that runs the script (directly or indirectly) then it's vital that only root (or people who have root privileges anyway) can write to the script file, and to the directory containing the script file, and to its parent directory and so on. It doesn't matter that anyone can read the script file (unless it contains a password or something, but that's a bad idea, if there's a password it should be in its own file, otherwise there's too much risk of accidentally leaking it e.g. by copy-pasting that section of the code in a question on this site).

                    – Gilles
                    Oct 10 '17 at 18:51






                  • 1





                    @alper No. Very few things require rebooting. After changing sudoers, you don't need to do anything special: sudo checks it each time.

                    – Gilles
                    Mar 18 at 19:02













                  116












                  116








                  116







                  If there are multiple matching entries in /etc/sudoers, sudo uses the last one. Therefore, if you can execute any command with a password prompt, and you want to be able to execute a particular command without a password prompt, you need the exception last.



                  myusername ALL = (ALL) ALL
                  myusername ALL = (root) NOPASSWD: /path/to/my/program


                  Note the use of (root), to allow the program to be run as root but not as other users. (Don't give more permissions than the minimum required unless you've thought out the implications.)



                  Note for readers who aren't running Ubuntu or who have changed the default sudo configuration (Ubuntu's sudo is ok by default): Running shell scripts with elevated privileges is risky, you need to start from a clean environment (once the shell has started, it's too late (see Allow setuid on shell scripts), so you need sudo to take care of that). Make sure that you have Defaults env_reset in /etc/sudoers or that this option is the compile-time default (sudo sudo -V | grep env should include Reset the environment to a default set of variables).






                  share|improve this answer















                  If there are multiple matching entries in /etc/sudoers, sudo uses the last one. Therefore, if you can execute any command with a password prompt, and you want to be able to execute a particular command without a password prompt, you need the exception last.



                  myusername ALL = (ALL) ALL
                  myusername ALL = (root) NOPASSWD: /path/to/my/program


                  Note the use of (root), to allow the program to be run as root but not as other users. (Don't give more permissions than the minimum required unless you've thought out the implications.)



                  Note for readers who aren't running Ubuntu or who have changed the default sudo configuration (Ubuntu's sudo is ok by default): Running shell scripts with elevated privileges is risky, you need to start from a clean environment (once the shell has started, it's too late (see Allow setuid on shell scripts), so you need sudo to take care of that). Make sure that you have Defaults env_reset in /etc/sudoers or that this option is the compile-time default (sudo sudo -V | grep env should include Reset the environment to a default set of variables).







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 13 '17 at 12:37









                  Community

                  1




                  1










                  answered May 12 '11 at 11:36









                  GillesGilles

                  545k12911071623




                  545k12911071623







                  • 2





                    ex to go root from jhon with sudo su an no pass -----> john ALL=(ALL) NOPASSWD: /bin/su

                    – bortunac
                    Jul 13 '14 at 14:05







                  • 4





                    @adrian If you want to allow arbitrary commands as root, make that john ALL=(ALL) NOPASSWD: all. There's no point in going via su.

                    – Gilles
                    Jul 13 '14 at 14:08











                  • Question: should I alter the permissions of my shell script so that it can get modified and read by root user only, for security? I'm thinking about an attacker modifying the script, which has all the permissions granted without the need of a password, so that it does what he/she wants. Obviously, the attacker can't even read sudoers file to know which scripts have this privilege, but can still try with all my custom scripts once he/she finds the folder in which they are stored in hope some are allowed, or something like that.

                    – Jeffrey Lebowski
                    Oct 10 '17 at 18:13







                  • 1





                    @JeffreyLebowski If you have a sudo rule that runs the script (directly or indirectly) then it's vital that only root (or people who have root privileges anyway) can write to the script file, and to the directory containing the script file, and to its parent directory and so on. It doesn't matter that anyone can read the script file (unless it contains a password or something, but that's a bad idea, if there's a password it should be in its own file, otherwise there's too much risk of accidentally leaking it e.g. by copy-pasting that section of the code in a question on this site).

                    – Gilles
                    Oct 10 '17 at 18:51






                  • 1





                    @alper No. Very few things require rebooting. After changing sudoers, you don't need to do anything special: sudo checks it each time.

                    – Gilles
                    Mar 18 at 19:02












                  • 2





                    ex to go root from jhon with sudo su an no pass -----> john ALL=(ALL) NOPASSWD: /bin/su

                    – bortunac
                    Jul 13 '14 at 14:05







                  • 4





                    @adrian If you want to allow arbitrary commands as root, make that john ALL=(ALL) NOPASSWD: all. There's no point in going via su.

                    – Gilles
                    Jul 13 '14 at 14:08











                  • Question: should I alter the permissions of my shell script so that it can get modified and read by root user only, for security? I'm thinking about an attacker modifying the script, which has all the permissions granted without the need of a password, so that it does what he/she wants. Obviously, the attacker can't even read sudoers file to know which scripts have this privilege, but can still try with all my custom scripts once he/she finds the folder in which they are stored in hope some are allowed, or something like that.

                    – Jeffrey Lebowski
                    Oct 10 '17 at 18:13







                  • 1





                    @JeffreyLebowski If you have a sudo rule that runs the script (directly or indirectly) then it's vital that only root (or people who have root privileges anyway) can write to the script file, and to the directory containing the script file, and to its parent directory and so on. It doesn't matter that anyone can read the script file (unless it contains a password or something, but that's a bad idea, if there's a password it should be in its own file, otherwise there's too much risk of accidentally leaking it e.g. by copy-pasting that section of the code in a question on this site).

                    – Gilles
                    Oct 10 '17 at 18:51






                  • 1





                    @alper No. Very few things require rebooting. After changing sudoers, you don't need to do anything special: sudo checks it each time.

                    – Gilles
                    Mar 18 at 19:02







                  2




                  2





                  ex to go root from jhon with sudo su an no pass -----> john ALL=(ALL) NOPASSWD: /bin/su

                  – bortunac
                  Jul 13 '14 at 14:05






                  ex to go root from jhon with sudo su an no pass -----> john ALL=(ALL) NOPASSWD: /bin/su

                  – bortunac
                  Jul 13 '14 at 14:05





                  4




                  4





                  @adrian If you want to allow arbitrary commands as root, make that john ALL=(ALL) NOPASSWD: all. There's no point in going via su.

                  – Gilles
                  Jul 13 '14 at 14:08





                  @adrian If you want to allow arbitrary commands as root, make that john ALL=(ALL) NOPASSWD: all. There's no point in going via su.

                  – Gilles
                  Jul 13 '14 at 14:08













                  Question: should I alter the permissions of my shell script so that it can get modified and read by root user only, for security? I'm thinking about an attacker modifying the script, which has all the permissions granted without the need of a password, so that it does what he/she wants. Obviously, the attacker can't even read sudoers file to know which scripts have this privilege, but can still try with all my custom scripts once he/she finds the folder in which they are stored in hope some are allowed, or something like that.

                  – Jeffrey Lebowski
                  Oct 10 '17 at 18:13






                  Question: should I alter the permissions of my shell script so that it can get modified and read by root user only, for security? I'm thinking about an attacker modifying the script, which has all the permissions granted without the need of a password, so that it does what he/she wants. Obviously, the attacker can't even read sudoers file to know which scripts have this privilege, but can still try with all my custom scripts once he/she finds the folder in which they are stored in hope some are allowed, or something like that.

                  – Jeffrey Lebowski
                  Oct 10 '17 at 18:13





                  1




                  1





                  @JeffreyLebowski If you have a sudo rule that runs the script (directly or indirectly) then it's vital that only root (or people who have root privileges anyway) can write to the script file, and to the directory containing the script file, and to its parent directory and so on. It doesn't matter that anyone can read the script file (unless it contains a password or something, but that's a bad idea, if there's a password it should be in its own file, otherwise there's too much risk of accidentally leaking it e.g. by copy-pasting that section of the code in a question on this site).

                  – Gilles
                  Oct 10 '17 at 18:51





                  @JeffreyLebowski If you have a sudo rule that runs the script (directly or indirectly) then it's vital that only root (or people who have root privileges anyway) can write to the script file, and to the directory containing the script file, and to its parent directory and so on. It doesn't matter that anyone can read the script file (unless it contains a password or something, but that's a bad idea, if there's a password it should be in its own file, otherwise there's too much risk of accidentally leaking it e.g. by copy-pasting that section of the code in a question on this site).

                  – Gilles
                  Oct 10 '17 at 18:51




                  1




                  1





                  @alper No. Very few things require rebooting. After changing sudoers, you don't need to do anything special: sudo checks it each time.

                  – Gilles
                  Mar 18 at 19:02





                  @alper No. Very few things require rebooting. After changing sudoers, you don't need to do anything special: sudo checks it each time.

                  – Gilles
                  Mar 18 at 19:02











                  21















                  WARNING: This answer has been deemed insecure. See comments below



                  Complete Solution: The following steps will help you achieve the desired output:




                  1. Create a new script file (replace create_dir.sh with your desired script name):



                    vim ~/create_dir.sh


                    The script will be created in the user’s home directory




                  2. Add some commands that only a root or sudo user can execute like creating a folder at the root directory level:



                    mkdir /abc


                    Note: Don’t add sudo to these commands. Save and exit (using :wq!)




                  3. Assign execute permissions to it using:



                    sudo chmod u+x create_dir.sh



                  4. Make changes so that this script doesn’t require a password.




                    1. Open the sudoers file:



                      sudo visudo -f /etc/sudoers



                    2. Add the following line at the end:



                      ahmad ALL=(root) NOPASSWD: /home/ahmad/create_dir.sh


                      Replace ahmad with whatever your username is. Also make sure this is the last line. Save and exit.





                  5. Now when running the command add sudo before it like:



                    sudo ./create_dir.sh


                    This will run the commands inside the script file without asking for a password.



                  Follow the easy steps mentioned here http://step4wd.com/2013/09/14/run-root-commands-in-linux-ubuntu-without-password/






                  share|improve this answer

























                  • It would be better if you provided the relevant steps here and used the link as a backup for more detailed information. That way your answer retains possible value even if that link would not be valid anymore.

                    – Anthon
                    Sep 14 '13 at 5:37






                  • 14





                    This advice is insecure. The sudo part of sudo chmod u+x create_dir.sh is unnecessary as the user has (presumably) ownership over his/her home dir. Since the user can write to create_dir.sh, you have effectively given a free root shell to that user.

                    – Lekensteyn
                    Jul 19 '14 at 8:36











                  • @Lekensteyn Which means also to any program running as the user. Might as well just allow the user to run anything with sudo without a password.

                    – pydsigner
                    May 23 '16 at 1:41






                  • 2





                    Am I missing something? I believe that the entire chmod is unnecessary, since you’re relying on sudo to elevate your privileges.

                    – G-Man
                    Jun 13 '18 at 14:57















                  21















                  WARNING: This answer has been deemed insecure. See comments below



                  Complete Solution: The following steps will help you achieve the desired output:




                  1. Create a new script file (replace create_dir.sh with your desired script name):



                    vim ~/create_dir.sh


                    The script will be created in the user’s home directory




                  2. Add some commands that only a root or sudo user can execute like creating a folder at the root directory level:



                    mkdir /abc


                    Note: Don’t add sudo to these commands. Save and exit (using :wq!)




                  3. Assign execute permissions to it using:



                    sudo chmod u+x create_dir.sh



                  4. Make changes so that this script doesn’t require a password.




                    1. Open the sudoers file:



                      sudo visudo -f /etc/sudoers



                    2. Add the following line at the end:



                      ahmad ALL=(root) NOPASSWD: /home/ahmad/create_dir.sh


                      Replace ahmad with whatever your username is. Also make sure this is the last line. Save and exit.





                  5. Now when running the command add sudo before it like:



                    sudo ./create_dir.sh


                    This will run the commands inside the script file without asking for a password.



                  Follow the easy steps mentioned here http://step4wd.com/2013/09/14/run-root-commands-in-linux-ubuntu-without-password/






                  share|improve this answer

























                  • It would be better if you provided the relevant steps here and used the link as a backup for more detailed information. That way your answer retains possible value even if that link would not be valid anymore.

                    – Anthon
                    Sep 14 '13 at 5:37






                  • 14





                    This advice is insecure. The sudo part of sudo chmod u+x create_dir.sh is unnecessary as the user has (presumably) ownership over his/her home dir. Since the user can write to create_dir.sh, you have effectively given a free root shell to that user.

                    – Lekensteyn
                    Jul 19 '14 at 8:36











                  • @Lekensteyn Which means also to any program running as the user. Might as well just allow the user to run anything with sudo without a password.

                    – pydsigner
                    May 23 '16 at 1:41






                  • 2





                    Am I missing something? I believe that the entire chmod is unnecessary, since you’re relying on sudo to elevate your privileges.

                    – G-Man
                    Jun 13 '18 at 14:57













                  21












                  21








                  21








                  WARNING: This answer has been deemed insecure. See comments below



                  Complete Solution: The following steps will help you achieve the desired output:




                  1. Create a new script file (replace create_dir.sh with your desired script name):



                    vim ~/create_dir.sh


                    The script will be created in the user’s home directory




                  2. Add some commands that only a root or sudo user can execute like creating a folder at the root directory level:



                    mkdir /abc


                    Note: Don’t add sudo to these commands. Save and exit (using :wq!)




                  3. Assign execute permissions to it using:



                    sudo chmod u+x create_dir.sh



                  4. Make changes so that this script doesn’t require a password.




                    1. Open the sudoers file:



                      sudo visudo -f /etc/sudoers



                    2. Add the following line at the end:



                      ahmad ALL=(root) NOPASSWD: /home/ahmad/create_dir.sh


                      Replace ahmad with whatever your username is. Also make sure this is the last line. Save and exit.





                  5. Now when running the command add sudo before it like:



                    sudo ./create_dir.sh


                    This will run the commands inside the script file without asking for a password.



                  Follow the easy steps mentioned here http://step4wd.com/2013/09/14/run-root-commands-in-linux-ubuntu-without-password/






                  share|improve this answer
















                  WARNING: This answer has been deemed insecure. See comments below



                  Complete Solution: The following steps will help you achieve the desired output:




                  1. Create a new script file (replace create_dir.sh with your desired script name):



                    vim ~/create_dir.sh


                    The script will be created in the user’s home directory




                  2. Add some commands that only a root or sudo user can execute like creating a folder at the root directory level:



                    mkdir /abc


                    Note: Don’t add sudo to these commands. Save and exit (using :wq!)




                  3. Assign execute permissions to it using:



                    sudo chmod u+x create_dir.sh



                  4. Make changes so that this script doesn’t require a password.




                    1. Open the sudoers file:



                      sudo visudo -f /etc/sudoers



                    2. Add the following line at the end:



                      ahmad ALL=(root) NOPASSWD: /home/ahmad/create_dir.sh


                      Replace ahmad with whatever your username is. Also make sure this is the last line. Save and exit.





                  5. Now when running the command add sudo before it like:



                    sudo ./create_dir.sh


                    This will run the commands inside the script file without asking for a password.



                  Follow the easy steps mentioned here http://step4wd.com/2013/09/14/run-root-commands-in-linux-ubuntu-without-password/







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 13 '18 at 14:57









                  Eldamir

                  1327




                  1327










                  answered Sep 14 '13 at 5:18









                  M. Ahmad ZafarM. Ahmad Zafar

                  32725




                  32725












                  • It would be better if you provided the relevant steps here and used the link as a backup for more detailed information. That way your answer retains possible value even if that link would not be valid anymore.

                    – Anthon
                    Sep 14 '13 at 5:37






                  • 14





                    This advice is insecure. The sudo part of sudo chmod u+x create_dir.sh is unnecessary as the user has (presumably) ownership over his/her home dir. Since the user can write to create_dir.sh, you have effectively given a free root shell to that user.

                    – Lekensteyn
                    Jul 19 '14 at 8:36











                  • @Lekensteyn Which means also to any program running as the user. Might as well just allow the user to run anything with sudo without a password.

                    – pydsigner
                    May 23 '16 at 1:41






                  • 2





                    Am I missing something? I believe that the entire chmod is unnecessary, since you’re relying on sudo to elevate your privileges.

                    – G-Man
                    Jun 13 '18 at 14:57

















                  • It would be better if you provided the relevant steps here and used the link as a backup for more detailed information. That way your answer retains possible value even if that link would not be valid anymore.

                    – Anthon
                    Sep 14 '13 at 5:37






                  • 14





                    This advice is insecure. The sudo part of sudo chmod u+x create_dir.sh is unnecessary as the user has (presumably) ownership over his/her home dir. Since the user can write to create_dir.sh, you have effectively given a free root shell to that user.

                    – Lekensteyn
                    Jul 19 '14 at 8:36











                  • @Lekensteyn Which means also to any program running as the user. Might as well just allow the user to run anything with sudo without a password.

                    – pydsigner
                    May 23 '16 at 1:41






                  • 2





                    Am I missing something? I believe that the entire chmod is unnecessary, since you’re relying on sudo to elevate your privileges.

                    – G-Man
                    Jun 13 '18 at 14:57
















                  It would be better if you provided the relevant steps here and used the link as a backup for more detailed information. That way your answer retains possible value even if that link would not be valid anymore.

                  – Anthon
                  Sep 14 '13 at 5:37





                  It would be better if you provided the relevant steps here and used the link as a backup for more detailed information. That way your answer retains possible value even if that link would not be valid anymore.

                  – Anthon
                  Sep 14 '13 at 5:37




                  14




                  14





                  This advice is insecure. The sudo part of sudo chmod u+x create_dir.sh is unnecessary as the user has (presumably) ownership over his/her home dir. Since the user can write to create_dir.sh, you have effectively given a free root shell to that user.

                  – Lekensteyn
                  Jul 19 '14 at 8:36





                  This advice is insecure. The sudo part of sudo chmod u+x create_dir.sh is unnecessary as the user has (presumably) ownership over his/her home dir. Since the user can write to create_dir.sh, you have effectively given a free root shell to that user.

                  – Lekensteyn
                  Jul 19 '14 at 8:36













                  @Lekensteyn Which means also to any program running as the user. Might as well just allow the user to run anything with sudo without a password.

                  – pydsigner
                  May 23 '16 at 1:41





                  @Lekensteyn Which means also to any program running as the user. Might as well just allow the user to run anything with sudo without a password.

                  – pydsigner
                  May 23 '16 at 1:41




                  2




                  2





                  Am I missing something? I believe that the entire chmod is unnecessary, since you’re relying on sudo to elevate your privileges.

                  – G-Man
                  Jun 13 '18 at 14:57





                  Am I missing something? I believe that the entire chmod is unnecessary, since you’re relying on sudo to elevate your privileges.

                  – G-Man
                  Jun 13 '18 at 14:57











                  8














                  I think your syntax is wrong. At least I use the following which works for me:



                  myusername ALL=(ALL) NOPASSWD: /path/to/executable





                  share|improve this answer


















                  • 6





                    The (ALL) part is optional, leaving it out has exactly the same effect. Having (root) would be better though, but its absence doesn't explain the problem.

                    – Gilles
                    May 12 '11 at 11:39











                  • +1 for sudo for this command and nothing else! No reason to break the entire system...

                    – Johan
                    May 12 '11 at 11:40






                  • 3





                    @Johan: That was already in the question.

                    – Gilles
                    May 12 '11 at 12:13















                  8














                  I think your syntax is wrong. At least I use the following which works for me:



                  myusername ALL=(ALL) NOPASSWD: /path/to/executable





                  share|improve this answer


















                  • 6





                    The (ALL) part is optional, leaving it out has exactly the same effect. Having (root) would be better though, but its absence doesn't explain the problem.

                    – Gilles
                    May 12 '11 at 11:39











                  • +1 for sudo for this command and nothing else! No reason to break the entire system...

                    – Johan
                    May 12 '11 at 11:40






                  • 3





                    @Johan: That was already in the question.

                    – Gilles
                    May 12 '11 at 12:13













                  8












                  8








                  8







                  I think your syntax is wrong. At least I use the following which works for me:



                  myusername ALL=(ALL) NOPASSWD: /path/to/executable





                  share|improve this answer













                  I think your syntax is wrong. At least I use the following which works for me:



                  myusername ALL=(ALL) NOPASSWD: /path/to/executable






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 12 '11 at 8:30









                  musiKkmusiKk

                  31819




                  31819







                  • 6





                    The (ALL) part is optional, leaving it out has exactly the same effect. Having (root) would be better though, but its absence doesn't explain the problem.

                    – Gilles
                    May 12 '11 at 11:39











                  • +1 for sudo for this command and nothing else! No reason to break the entire system...

                    – Johan
                    May 12 '11 at 11:40






                  • 3





                    @Johan: That was already in the question.

                    – Gilles
                    May 12 '11 at 12:13












                  • 6





                    The (ALL) part is optional, leaving it out has exactly the same effect. Having (root) would be better though, but its absence doesn't explain the problem.

                    – Gilles
                    May 12 '11 at 11:39











                  • +1 for sudo for this command and nothing else! No reason to break the entire system...

                    – Johan
                    May 12 '11 at 11:40






                  • 3





                    @Johan: That was already in the question.

                    – Gilles
                    May 12 '11 at 12:13







                  6




                  6





                  The (ALL) part is optional, leaving it out has exactly the same effect. Having (root) would be better though, but its absence doesn't explain the problem.

                  – Gilles
                  May 12 '11 at 11:39





                  The (ALL) part is optional, leaving it out has exactly the same effect. Having (root) would be better though, but its absence doesn't explain the problem.

                  – Gilles
                  May 12 '11 at 11:39













                  +1 for sudo for this command and nothing else! No reason to break the entire system...

                  – Johan
                  May 12 '11 at 11:40





                  +1 for sudo for this command and nothing else! No reason to break the entire system...

                  – Johan
                  May 12 '11 at 11:40




                  3




                  3





                  @Johan: That was already in the question.

                  – Gilles
                  May 12 '11 at 12:13





                  @Johan: That was already in the question.

                  – Gilles
                  May 12 '11 at 12:13











                  4














                  Verify that sudo is not aliased. Run like this



                  /usr/bin/sudo /path/to/my/program


                  For example a shell alias like this one:



                  alias sudo="sudo env PATH=$PATH"


                  may cause this behaviour.






                  share|improve this answer

























                  • You are right, my comment was out of order here, sorry for that. Nevertheless I'm intrigued - how do you expect aliasing to change the processing of sudoers by sudo. Or are you talking about redirecting sudo to something that always prints this error message to scoop passwords? That is unlikely the case here...

                    – peterph
                    Jul 19 '14 at 8:18






                  • 2





                    I was having the same problem as the OP. It turned out to be caused by having alias sudo="sudo env PATH=$PATH" in my ~/.bashrc. Rather than just solving it for myself and blindly just going about my business, I submitted my answer as a possible solution for anyone else that comes along this thread.

                    – Sepero
                    Jul 19 '14 at 22:50












                  • That's fine, but when it is not obvious (which in this case isn't at least to some people) it is good to put an explanation into the answer to provide some context and prevent people from blindly using magic incantations. +2 (-(-1) + +1). :)

                    – peterph
                    Jul 24 '14 at 22:45















                  4














                  Verify that sudo is not aliased. Run like this



                  /usr/bin/sudo /path/to/my/program


                  For example a shell alias like this one:



                  alias sudo="sudo env PATH=$PATH"


                  may cause this behaviour.






                  share|improve this answer

























                  • You are right, my comment was out of order here, sorry for that. Nevertheless I'm intrigued - how do you expect aliasing to change the processing of sudoers by sudo. Or are you talking about redirecting sudo to something that always prints this error message to scoop passwords? That is unlikely the case here...

                    – peterph
                    Jul 19 '14 at 8:18






                  • 2





                    I was having the same problem as the OP. It turned out to be caused by having alias sudo="sudo env PATH=$PATH" in my ~/.bashrc. Rather than just solving it for myself and blindly just going about my business, I submitted my answer as a possible solution for anyone else that comes along this thread.

                    – Sepero
                    Jul 19 '14 at 22:50












                  • That's fine, but when it is not obvious (which in this case isn't at least to some people) it is good to put an explanation into the answer to provide some context and prevent people from blindly using magic incantations. +2 (-(-1) + +1). :)

                    – peterph
                    Jul 24 '14 at 22:45













                  4












                  4








                  4







                  Verify that sudo is not aliased. Run like this



                  /usr/bin/sudo /path/to/my/program


                  For example a shell alias like this one:



                  alias sudo="sudo env PATH=$PATH"


                  may cause this behaviour.






                  share|improve this answer















                  Verify that sudo is not aliased. Run like this



                  /usr/bin/sudo /path/to/my/program


                  For example a shell alias like this one:



                  alias sudo="sudo env PATH=$PATH"


                  may cause this behaviour.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 24 '14 at 22:42









                  peterph

                  23.8k24558




                  23.8k24558










                  answered Jul 18 '14 at 23:54









                  SeperoSepero

                  59931226




                  59931226












                  • You are right, my comment was out of order here, sorry for that. Nevertheless I'm intrigued - how do you expect aliasing to change the processing of sudoers by sudo. Or are you talking about redirecting sudo to something that always prints this error message to scoop passwords? That is unlikely the case here...

                    – peterph
                    Jul 19 '14 at 8:18






                  • 2





                    I was having the same problem as the OP. It turned out to be caused by having alias sudo="sudo env PATH=$PATH" in my ~/.bashrc. Rather than just solving it for myself and blindly just going about my business, I submitted my answer as a possible solution for anyone else that comes along this thread.

                    – Sepero
                    Jul 19 '14 at 22:50












                  • That's fine, but when it is not obvious (which in this case isn't at least to some people) it is good to put an explanation into the answer to provide some context and prevent people from blindly using magic incantations. +2 (-(-1) + +1). :)

                    – peterph
                    Jul 24 '14 at 22:45

















                  • You are right, my comment was out of order here, sorry for that. Nevertheless I'm intrigued - how do you expect aliasing to change the processing of sudoers by sudo. Or are you talking about redirecting sudo to something that always prints this error message to scoop passwords? That is unlikely the case here...

                    – peterph
                    Jul 19 '14 at 8:18






                  • 2





                    I was having the same problem as the OP. It turned out to be caused by having alias sudo="sudo env PATH=$PATH" in my ~/.bashrc. Rather than just solving it for myself and blindly just going about my business, I submitted my answer as a possible solution for anyone else that comes along this thread.

                    – Sepero
                    Jul 19 '14 at 22:50












                  • That's fine, but when it is not obvious (which in this case isn't at least to some people) it is good to put an explanation into the answer to provide some context and prevent people from blindly using magic incantations. +2 (-(-1) + +1). :)

                    – peterph
                    Jul 24 '14 at 22:45
















                  You are right, my comment was out of order here, sorry for that. Nevertheless I'm intrigued - how do you expect aliasing to change the processing of sudoers by sudo. Or are you talking about redirecting sudo to something that always prints this error message to scoop passwords? That is unlikely the case here...

                  – peterph
                  Jul 19 '14 at 8:18





                  You are right, my comment was out of order here, sorry for that. Nevertheless I'm intrigued - how do you expect aliasing to change the processing of sudoers by sudo. Or are you talking about redirecting sudo to something that always prints this error message to scoop passwords? That is unlikely the case here...

                  – peterph
                  Jul 19 '14 at 8:18




                  2




                  2





                  I was having the same problem as the OP. It turned out to be caused by having alias sudo="sudo env PATH=$PATH" in my ~/.bashrc. Rather than just solving it for myself and blindly just going about my business, I submitted my answer as a possible solution for anyone else that comes along this thread.

                  – Sepero
                  Jul 19 '14 at 22:50






                  I was having the same problem as the OP. It turned out to be caused by having alias sudo="sudo env PATH=$PATH" in my ~/.bashrc. Rather than just solving it for myself and blindly just going about my business, I submitted my answer as a possible solution for anyone else that comes along this thread.

                  – Sepero
                  Jul 19 '14 at 22:50














                  That's fine, but when it is not obvious (which in this case isn't at least to some people) it is good to put an explanation into the answer to provide some context and prevent people from blindly using magic incantations. +2 (-(-1) + +1). :)

                  – peterph
                  Jul 24 '14 at 22:45





                  That's fine, but when it is not obvious (which in this case isn't at least to some people) it is good to put an explanation into the answer to provide some context and prevent people from blindly using magic incantations. +2 (-(-1) + +1). :)

                  – peterph
                  Jul 24 '14 at 22:45











                  4














                  In some distros, Manjaro in my case, there is a file that overrides the /etc/sudoers file



                  sudo cat /etc/sudoers.d/10-installer


                  • the ONLY way to see it is under root privilegies, you cannot list this directory without it.

                  There you will find something like this:



                  youruser ALL=(ALL)


                  You can delete that file, and will use cfg in /etc/sudoers file




                  /etc/sudoers:



                  In the sudoers file you must put something like:



                  %group ALL=(ALL) NOPASSWD: ALL


                  or



                  youruser ALL=(ALL) NOPASSWD: ALL


                  or



                  youruser ALL=(ALL) NOPASSWD: /path/to/executable


                  I hope this helps somebody :).






                  share|improve this answer



























                    4














                    In some distros, Manjaro in my case, there is a file that overrides the /etc/sudoers file



                    sudo cat /etc/sudoers.d/10-installer


                    • the ONLY way to see it is under root privilegies, you cannot list this directory without it.

                    There you will find something like this:



                    youruser ALL=(ALL)


                    You can delete that file, and will use cfg in /etc/sudoers file




                    /etc/sudoers:



                    In the sudoers file you must put something like:



                    %group ALL=(ALL) NOPASSWD: ALL


                    or



                    youruser ALL=(ALL) NOPASSWD: ALL


                    or



                    youruser ALL=(ALL) NOPASSWD: /path/to/executable


                    I hope this helps somebody :).






                    share|improve this answer

























                      4












                      4








                      4







                      In some distros, Manjaro in my case, there is a file that overrides the /etc/sudoers file



                      sudo cat /etc/sudoers.d/10-installer


                      • the ONLY way to see it is under root privilegies, you cannot list this directory without it.

                      There you will find something like this:



                      youruser ALL=(ALL)


                      You can delete that file, and will use cfg in /etc/sudoers file




                      /etc/sudoers:



                      In the sudoers file you must put something like:



                      %group ALL=(ALL) NOPASSWD: ALL


                      or



                      youruser ALL=(ALL) NOPASSWD: ALL


                      or



                      youruser ALL=(ALL) NOPASSWD: /path/to/executable


                      I hope this helps somebody :).






                      share|improve this answer













                      In some distros, Manjaro in my case, there is a file that overrides the /etc/sudoers file



                      sudo cat /etc/sudoers.d/10-installer


                      • the ONLY way to see it is under root privilegies, you cannot list this directory without it.

                      There you will find something like this:



                      youruser ALL=(ALL)


                      You can delete that file, and will use cfg in /etc/sudoers file




                      /etc/sudoers:



                      In the sudoers file you must put something like:



                      %group ALL=(ALL) NOPASSWD: ALL


                      or



                      youruser ALL=(ALL) NOPASSWD: ALL


                      or



                      youruser ALL=(ALL) NOPASSWD: /path/to/executable


                      I hope this helps somebody :).







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 17 '15 at 20:48









                      LyoneelLyoneel

                      1412




                      1412





















                          2














                          When you execute your script you need to run it as sudo /path/to/my/script.



                          Edit: Based on your comment to another answer, you want to run this from an icon. You will need to create a .desktop file that executes your program with sudo, just like on the terminal.



                          You could also consider using gtk-sudo for a visual password prompt.



                          You should probably consider the idea that you shouldn't be running things as root and that changing the system farther down the road so that you don't need root permissions at all would be a better way to go.






                          share|improve this answer




















                          • 6





                            Do not make shell scripts setuid. See Allow setuid on shell scripts.

                            – Gilles
                            May 12 '11 at 11:38











                          • I considered not even mentioning it because it's such a bad option. I just deleted it because I'm worried this asker might use the advice even with the warning that it was bad advice!

                            – Caleb
                            May 12 '11 at 11:41















                          2














                          When you execute your script you need to run it as sudo /path/to/my/script.



                          Edit: Based on your comment to another answer, you want to run this from an icon. You will need to create a .desktop file that executes your program with sudo, just like on the terminal.



                          You could also consider using gtk-sudo for a visual password prompt.



                          You should probably consider the idea that you shouldn't be running things as root and that changing the system farther down the road so that you don't need root permissions at all would be a better way to go.






                          share|improve this answer




















                          • 6





                            Do not make shell scripts setuid. See Allow setuid on shell scripts.

                            – Gilles
                            May 12 '11 at 11:38











                          • I considered not even mentioning it because it's such a bad option. I just deleted it because I'm worried this asker might use the advice even with the warning that it was bad advice!

                            – Caleb
                            May 12 '11 at 11:41













                          2












                          2








                          2







                          When you execute your script you need to run it as sudo /path/to/my/script.



                          Edit: Based on your comment to another answer, you want to run this from an icon. You will need to create a .desktop file that executes your program with sudo, just like on the terminal.



                          You could also consider using gtk-sudo for a visual password prompt.



                          You should probably consider the idea that you shouldn't be running things as root and that changing the system farther down the road so that you don't need root permissions at all would be a better way to go.






                          share|improve this answer















                          When you execute your script you need to run it as sudo /path/to/my/script.



                          Edit: Based on your comment to another answer, you want to run this from an icon. You will need to create a .desktop file that executes your program with sudo, just like on the terminal.



                          You could also consider using gtk-sudo for a visual password prompt.



                          You should probably consider the idea that you shouldn't be running things as root and that changing the system farther down the road so that you don't need root permissions at all would be a better way to go.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Aug 17 '11 at 0:29









                          Michael Mrozek

                          62.2k29193213




                          62.2k29193213










                          answered May 12 '11 at 8:31









                          CalebCaleb

                          51.8k9150194




                          51.8k9150194







                          • 6





                            Do not make shell scripts setuid. See Allow setuid on shell scripts.

                            – Gilles
                            May 12 '11 at 11:38











                          • I considered not even mentioning it because it's such a bad option. I just deleted it because I'm worried this asker might use the advice even with the warning that it was bad advice!

                            – Caleb
                            May 12 '11 at 11:41












                          • 6





                            Do not make shell scripts setuid. See Allow setuid on shell scripts.

                            – Gilles
                            May 12 '11 at 11:38











                          • I considered not even mentioning it because it's such a bad option. I just deleted it because I'm worried this asker might use the advice even with the warning that it was bad advice!

                            – Caleb
                            May 12 '11 at 11:41







                          6




                          6





                          Do not make shell scripts setuid. See Allow setuid on shell scripts.

                          – Gilles
                          May 12 '11 at 11:38





                          Do not make shell scripts setuid. See Allow setuid on shell scripts.

                          – Gilles
                          May 12 '11 at 11:38













                          I considered not even mentioning it because it's such a bad option. I just deleted it because I'm worried this asker might use the advice even with the warning that it was bad advice!

                          – Caleb
                          May 12 '11 at 11:41





                          I considered not even mentioning it because it's such a bad option. I just deleted it because I'm worried this asker might use the advice even with the warning that it was bad advice!

                          – Caleb
                          May 12 '11 at 11:41











                          2














                          This solved the issue for me (also tried some of the other answers, that might have helped):



                          The script I was calling was in /usr/bin, a directory that I don't have write permissions to (though I can usually read any files there). The script was chmodded +x (executable permisison), but it still didn't work. Moving this file to a path in my home directory, instead of /usr/bin, I was finally able to call it with sudo without entering a password.



                          Also something I doubted about (clarifying for future readers): You need to run your script as sudo. Type sudo when calling the script. Don't use sudo for the command inside your script that actually needs root (changing keyboard backlight in my case). Perhaps that also works, but you don't need to, and it seems like a better solution not to.






                          share|improve this answer

























                          • The second paragraph had the answer to my problem

                            – M. Ahmad Zafar
                            Sep 13 '13 at 8:02











                          • @MuhammadAhmadZafar Glad it helped!

                            – Luc
                            Sep 13 '13 at 10:53






                          • 3





                            Actually using sudo inside of a script is perfectly fine provided you have the appropriate rights (set in sudoers) to run the command in question without a password. It makes things a bit more secure.

                            – peterph
                            Jul 19 '14 at 8:21











                          • could really use this answer re-written as a step-by-step 'this is how you do it' rather than as a dialogue with the other answers

                            – Walrus the Cat
                            Nov 28 '17 at 22:31











                          • @WalrustheCat Good point. Re-reading my answer, I think I might have been confused a little myself. Right now though, I don't remember what the exact situation was so I can't really do a better writeup. If you figure it out, perhaps a combination of several answers, by all means submit a new answer!

                            – Luc
                            Nov 29 '17 at 7:24















                          2














                          This solved the issue for me (also tried some of the other answers, that might have helped):



                          The script I was calling was in /usr/bin, a directory that I don't have write permissions to (though I can usually read any files there). The script was chmodded +x (executable permisison), but it still didn't work. Moving this file to a path in my home directory, instead of /usr/bin, I was finally able to call it with sudo without entering a password.



                          Also something I doubted about (clarifying for future readers): You need to run your script as sudo. Type sudo when calling the script. Don't use sudo for the command inside your script that actually needs root (changing keyboard backlight in my case). Perhaps that also works, but you don't need to, and it seems like a better solution not to.






                          share|improve this answer

























                          • The second paragraph had the answer to my problem

                            – M. Ahmad Zafar
                            Sep 13 '13 at 8:02











                          • @MuhammadAhmadZafar Glad it helped!

                            – Luc
                            Sep 13 '13 at 10:53






                          • 3





                            Actually using sudo inside of a script is perfectly fine provided you have the appropriate rights (set in sudoers) to run the command in question without a password. It makes things a bit more secure.

                            – peterph
                            Jul 19 '14 at 8:21











                          • could really use this answer re-written as a step-by-step 'this is how you do it' rather than as a dialogue with the other answers

                            – Walrus the Cat
                            Nov 28 '17 at 22:31











                          • @WalrustheCat Good point. Re-reading my answer, I think I might have been confused a little myself. Right now though, I don't remember what the exact situation was so I can't really do a better writeup. If you figure it out, perhaps a combination of several answers, by all means submit a new answer!

                            – Luc
                            Nov 29 '17 at 7:24













                          2












                          2








                          2







                          This solved the issue for me (also tried some of the other answers, that might have helped):



                          The script I was calling was in /usr/bin, a directory that I don't have write permissions to (though I can usually read any files there). The script was chmodded +x (executable permisison), but it still didn't work. Moving this file to a path in my home directory, instead of /usr/bin, I was finally able to call it with sudo without entering a password.



                          Also something I doubted about (clarifying for future readers): You need to run your script as sudo. Type sudo when calling the script. Don't use sudo for the command inside your script that actually needs root (changing keyboard backlight in my case). Perhaps that also works, but you don't need to, and it seems like a better solution not to.






                          share|improve this answer















                          This solved the issue for me (also tried some of the other answers, that might have helped):



                          The script I was calling was in /usr/bin, a directory that I don't have write permissions to (though I can usually read any files there). The script was chmodded +x (executable permisison), but it still didn't work. Moving this file to a path in my home directory, instead of /usr/bin, I was finally able to call it with sudo without entering a password.



                          Also something I doubted about (clarifying for future readers): You need to run your script as sudo. Type sudo when calling the script. Don't use sudo for the command inside your script that actually needs root (changing keyboard backlight in my case). Perhaps that also works, but you don't need to, and it seems like a better solution not to.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jul 19 '14 at 8:21









                          peterph

                          23.8k24558




                          23.8k24558










                          answered Jul 18 '13 at 17:44









                          LucLuc

                          9841921




                          9841921












                          • The second paragraph had the answer to my problem

                            – M. Ahmad Zafar
                            Sep 13 '13 at 8:02











                          • @MuhammadAhmadZafar Glad it helped!

                            – Luc
                            Sep 13 '13 at 10:53






                          • 3





                            Actually using sudo inside of a script is perfectly fine provided you have the appropriate rights (set in sudoers) to run the command in question without a password. It makes things a bit more secure.

                            – peterph
                            Jul 19 '14 at 8:21











                          • could really use this answer re-written as a step-by-step 'this is how you do it' rather than as a dialogue with the other answers

                            – Walrus the Cat
                            Nov 28 '17 at 22:31











                          • @WalrustheCat Good point. Re-reading my answer, I think I might have been confused a little myself. Right now though, I don't remember what the exact situation was so I can't really do a better writeup. If you figure it out, perhaps a combination of several answers, by all means submit a new answer!

                            – Luc
                            Nov 29 '17 at 7:24

















                          • The second paragraph had the answer to my problem

                            – M. Ahmad Zafar
                            Sep 13 '13 at 8:02











                          • @MuhammadAhmadZafar Glad it helped!

                            – Luc
                            Sep 13 '13 at 10:53






                          • 3





                            Actually using sudo inside of a script is perfectly fine provided you have the appropriate rights (set in sudoers) to run the command in question without a password. It makes things a bit more secure.

                            – peterph
                            Jul 19 '14 at 8:21











                          • could really use this answer re-written as a step-by-step 'this is how you do it' rather than as a dialogue with the other answers

                            – Walrus the Cat
                            Nov 28 '17 at 22:31











                          • @WalrustheCat Good point. Re-reading my answer, I think I might have been confused a little myself. Right now though, I don't remember what the exact situation was so I can't really do a better writeup. If you figure it out, perhaps a combination of several answers, by all means submit a new answer!

                            – Luc
                            Nov 29 '17 at 7:24
















                          The second paragraph had the answer to my problem

                          – M. Ahmad Zafar
                          Sep 13 '13 at 8:02





                          The second paragraph had the answer to my problem

                          – M. Ahmad Zafar
                          Sep 13 '13 at 8:02













                          @MuhammadAhmadZafar Glad it helped!

                          – Luc
                          Sep 13 '13 at 10:53





                          @MuhammadAhmadZafar Glad it helped!

                          – Luc
                          Sep 13 '13 at 10:53




                          3




                          3





                          Actually using sudo inside of a script is perfectly fine provided you have the appropriate rights (set in sudoers) to run the command in question without a password. It makes things a bit more secure.

                          – peterph
                          Jul 19 '14 at 8:21





                          Actually using sudo inside of a script is perfectly fine provided you have the appropriate rights (set in sudoers) to run the command in question without a password. It makes things a bit more secure.

                          – peterph
                          Jul 19 '14 at 8:21













                          could really use this answer re-written as a step-by-step 'this is how you do it' rather than as a dialogue with the other answers

                          – Walrus the Cat
                          Nov 28 '17 at 22:31





                          could really use this answer re-written as a step-by-step 'this is how you do it' rather than as a dialogue with the other answers

                          – Walrus the Cat
                          Nov 28 '17 at 22:31













                          @WalrustheCat Good point. Re-reading my answer, I think I might have been confused a little myself. Right now though, I don't remember what the exact situation was so I can't really do a better writeup. If you figure it out, perhaps a combination of several answers, by all means submit a new answer!

                          – Luc
                          Nov 29 '17 at 7:24





                          @WalrustheCat Good point. Re-reading my answer, I think I might have been confused a little myself. Right now though, I don't remember what the exact situation was so I can't really do a better writeup. If you figure it out, perhaps a combination of several answers, by all means submit a new answer!

                          – Luc
                          Nov 29 '17 at 7:24











                          2














                          If you want to avoid having to use sudo nor have to change the sudoers config file, you can use:



                          sudo chown root:root path/to/command/COMMAND_NAME
                          sudo chmod 4775 path/to/command/COMMAND_NAME


                          This will make the command run as root without the need of sudo.






                          share|improve this answer

























                          • Wow, I never heard of this solution before, mind boggling

                            – somethingSomething
                            Nov 10 '18 at 14:18















                          2














                          If you want to avoid having to use sudo nor have to change the sudoers config file, you can use:



                          sudo chown root:root path/to/command/COMMAND_NAME
                          sudo chmod 4775 path/to/command/COMMAND_NAME


                          This will make the command run as root without the need of sudo.






                          share|improve this answer

























                          • Wow, I never heard of this solution before, mind boggling

                            – somethingSomething
                            Nov 10 '18 at 14:18













                          2












                          2








                          2







                          If you want to avoid having to use sudo nor have to change the sudoers config file, you can use:



                          sudo chown root:root path/to/command/COMMAND_NAME
                          sudo chmod 4775 path/to/command/COMMAND_NAME


                          This will make the command run as root without the need of sudo.






                          share|improve this answer















                          If you want to avoid having to use sudo nor have to change the sudoers config file, you can use:



                          sudo chown root:root path/to/command/COMMAND_NAME
                          sudo chmod 4775 path/to/command/COMMAND_NAME


                          This will make the command run as root without the need of sudo.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 25 '17 at 9:19









                          Thomas

                          4,11561430




                          4,11561430










                          answered Mar 25 '17 at 9:10









                          linuxgnurulinuxgnuru

                          1264




                          1264












                          • Wow, I never heard of this solution before, mind boggling

                            – somethingSomething
                            Nov 10 '18 at 14:18

















                          • Wow, I never heard of this solution before, mind boggling

                            – somethingSomething
                            Nov 10 '18 at 14:18
















                          Wow, I never heard of this solution before, mind boggling

                          – somethingSomething
                          Nov 10 '18 at 14:18





                          Wow, I never heard of this solution before, mind boggling

                          – somethingSomething
                          Nov 10 '18 at 14:18











                          1














                          Another possibility might be to install, configure, then use the super command to run your script as



                          super /path/to/your/script



                          If you want to run some binary executable (e.g. that you have compiled into ELF binary from some C source code) -which is not a script- as root, you might consider making it setuid (and actually /bin/login, /usr/bin/sudo and /bin/su and super are all using that technique). However, be very careful, you could open a huge security hole.



                          Concretely, your program should be paranoically coded (so check all arguments and the environment and outside conditions before "acting", assuming a potentially hostile user), then you could use seteuid(2) and friends (see also setreuid(2)) carefully (see also capabilities(7) & credentials(7) & execve(2)...)



                          You'll use chmod u+s (read chmod(1)) when installing such a binary.



                          But be very careful.



                          Read many things about setuid, including Advanced Linux Programming, before coding such a thing.



                          Notice that a script, or any shebang-ed thing, cannot be setuid. But you could code (in C) a small setuid-binary wrapping it.






                          share|improve this answer





























                            1














                            Another possibility might be to install, configure, then use the super command to run your script as



                            super /path/to/your/script



                            If you want to run some binary executable (e.g. that you have compiled into ELF binary from some C source code) -which is not a script- as root, you might consider making it setuid (and actually /bin/login, /usr/bin/sudo and /bin/su and super are all using that technique). However, be very careful, you could open a huge security hole.



                            Concretely, your program should be paranoically coded (so check all arguments and the environment and outside conditions before "acting", assuming a potentially hostile user), then you could use seteuid(2) and friends (see also setreuid(2)) carefully (see also capabilities(7) & credentials(7) & execve(2)...)



                            You'll use chmod u+s (read chmod(1)) when installing such a binary.



                            But be very careful.



                            Read many things about setuid, including Advanced Linux Programming, before coding such a thing.



                            Notice that a script, or any shebang-ed thing, cannot be setuid. But you could code (in C) a small setuid-binary wrapping it.






                            share|improve this answer



























                              1












                              1








                              1







                              Another possibility might be to install, configure, then use the super command to run your script as



                              super /path/to/your/script



                              If you want to run some binary executable (e.g. that you have compiled into ELF binary from some C source code) -which is not a script- as root, you might consider making it setuid (and actually /bin/login, /usr/bin/sudo and /bin/su and super are all using that technique). However, be very careful, you could open a huge security hole.



                              Concretely, your program should be paranoically coded (so check all arguments and the environment and outside conditions before "acting", assuming a potentially hostile user), then you could use seteuid(2) and friends (see also setreuid(2)) carefully (see also capabilities(7) & credentials(7) & execve(2)...)



                              You'll use chmod u+s (read chmod(1)) when installing such a binary.



                              But be very careful.



                              Read many things about setuid, including Advanced Linux Programming, before coding such a thing.



                              Notice that a script, or any shebang-ed thing, cannot be setuid. But you could code (in C) a small setuid-binary wrapping it.






                              share|improve this answer















                              Another possibility might be to install, configure, then use the super command to run your script as



                              super /path/to/your/script



                              If you want to run some binary executable (e.g. that you have compiled into ELF binary from some C source code) -which is not a script- as root, you might consider making it setuid (and actually /bin/login, /usr/bin/sudo and /bin/su and super are all using that technique). However, be very careful, you could open a huge security hole.



                              Concretely, your program should be paranoically coded (so check all arguments and the environment and outside conditions before "acting", assuming a potentially hostile user), then you could use seteuid(2) and friends (see also setreuid(2)) carefully (see also capabilities(7) & credentials(7) & execve(2)...)



                              You'll use chmod u+s (read chmod(1)) when installing such a binary.



                              But be very careful.



                              Read many things about setuid, including Advanced Linux Programming, before coding such a thing.



                              Notice that a script, or any shebang-ed thing, cannot be setuid. But you could code (in C) a small setuid-binary wrapping it.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jul 24 '17 at 11:06

























                              answered Jul 24 '17 at 11:00









                              Basile StarynkevitchBasile Starynkevitch

                              8,1412041




                              8,1412041





















                                  0














                                  Ideally if you are customizing what commands can be run via sudo you should be making these changes in a separate file under /etc/sudoers.d/ instead of editing the sudoers file directly. You should also always use visudo to edit the file(s). You should NEVER grant NOPASSWD on ALL commands.



                                  Example:
                                  sudo visudo -f /etc/sudoers.d/mynotriskycommand



                                  Insert your line granting permission:
                                  myuser ALL= NOPASSWD: /path/to/your/program



                                  Then save and exit and visudo will warn you if you have any syntax errors.



                                  You can run sudo -l to see the permissions that your user has been granted, if any of the user specific NOPASSWD commands appear BEFORE any %groupyouarein ALL=(ALL) ALL command in the output you will be prompted for your password.



                                  If you find yourself creating lots of these sudoers.d files then perhaps you will want to create them named per user so they are easier to visualize. Keep in mind that the ordering of the FILE NAMES and of the RULES within the file is very important, the LAST one loaded wins, whether it is MORE or LESS permissive than the previous entries.




                                  You can control the file name ordering by using a prefix of 00-99 or aa/bb/cc, though also keep in mind that if you have ANY files that don't have numeric prefix, they will load after the numbered files, overriding the settings. This is because depending on your language settings the "lexical sorting" the shell uses sorts numbers first and then may interleave upper and lowercase when sorting in "ascending" order.




                                  Try running printf '%sn' 0..99,A-Z,a-z | sort and printf '%sn' 0..99,A-Z,a-z | LANG=C sort to see whether your current language prints AaBbCc etc or ABC then abc to determine what the best "last" letter prefix to use would be.






                                  share|improve this answer



























                                    0














                                    Ideally if you are customizing what commands can be run via sudo you should be making these changes in a separate file under /etc/sudoers.d/ instead of editing the sudoers file directly. You should also always use visudo to edit the file(s). You should NEVER grant NOPASSWD on ALL commands.



                                    Example:
                                    sudo visudo -f /etc/sudoers.d/mynotriskycommand



                                    Insert your line granting permission:
                                    myuser ALL= NOPASSWD: /path/to/your/program



                                    Then save and exit and visudo will warn you if you have any syntax errors.



                                    You can run sudo -l to see the permissions that your user has been granted, if any of the user specific NOPASSWD commands appear BEFORE any %groupyouarein ALL=(ALL) ALL command in the output you will be prompted for your password.



                                    If you find yourself creating lots of these sudoers.d files then perhaps you will want to create them named per user so they are easier to visualize. Keep in mind that the ordering of the FILE NAMES and of the RULES within the file is very important, the LAST one loaded wins, whether it is MORE or LESS permissive than the previous entries.




                                    You can control the file name ordering by using a prefix of 00-99 or aa/bb/cc, though also keep in mind that if you have ANY files that don't have numeric prefix, they will load after the numbered files, overriding the settings. This is because depending on your language settings the "lexical sorting" the shell uses sorts numbers first and then may interleave upper and lowercase when sorting in "ascending" order.




                                    Try running printf '%sn' 0..99,A-Z,a-z | sort and printf '%sn' 0..99,A-Z,a-z | LANG=C sort to see whether your current language prints AaBbCc etc or ABC then abc to determine what the best "last" letter prefix to use would be.






                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      Ideally if you are customizing what commands can be run via sudo you should be making these changes in a separate file under /etc/sudoers.d/ instead of editing the sudoers file directly. You should also always use visudo to edit the file(s). You should NEVER grant NOPASSWD on ALL commands.



                                      Example:
                                      sudo visudo -f /etc/sudoers.d/mynotriskycommand



                                      Insert your line granting permission:
                                      myuser ALL= NOPASSWD: /path/to/your/program



                                      Then save and exit and visudo will warn you if you have any syntax errors.



                                      You can run sudo -l to see the permissions that your user has been granted, if any of the user specific NOPASSWD commands appear BEFORE any %groupyouarein ALL=(ALL) ALL command in the output you will be prompted for your password.



                                      If you find yourself creating lots of these sudoers.d files then perhaps you will want to create them named per user so they are easier to visualize. Keep in mind that the ordering of the FILE NAMES and of the RULES within the file is very important, the LAST one loaded wins, whether it is MORE or LESS permissive than the previous entries.




                                      You can control the file name ordering by using a prefix of 00-99 or aa/bb/cc, though also keep in mind that if you have ANY files that don't have numeric prefix, they will load after the numbered files, overriding the settings. This is because depending on your language settings the "lexical sorting" the shell uses sorts numbers first and then may interleave upper and lowercase when sorting in "ascending" order.




                                      Try running printf '%sn' 0..99,A-Z,a-z | sort and printf '%sn' 0..99,A-Z,a-z | LANG=C sort to see whether your current language prints AaBbCc etc or ABC then abc to determine what the best "last" letter prefix to use would be.






                                      share|improve this answer













                                      Ideally if you are customizing what commands can be run via sudo you should be making these changes in a separate file under /etc/sudoers.d/ instead of editing the sudoers file directly. You should also always use visudo to edit the file(s). You should NEVER grant NOPASSWD on ALL commands.



                                      Example:
                                      sudo visudo -f /etc/sudoers.d/mynotriskycommand



                                      Insert your line granting permission:
                                      myuser ALL= NOPASSWD: /path/to/your/program



                                      Then save and exit and visudo will warn you if you have any syntax errors.



                                      You can run sudo -l to see the permissions that your user has been granted, if any of the user specific NOPASSWD commands appear BEFORE any %groupyouarein ALL=(ALL) ALL command in the output you will be prompted for your password.



                                      If you find yourself creating lots of these sudoers.d files then perhaps you will want to create them named per user so they are easier to visualize. Keep in mind that the ordering of the FILE NAMES and of the RULES within the file is very important, the LAST one loaded wins, whether it is MORE or LESS permissive than the previous entries.




                                      You can control the file name ordering by using a prefix of 00-99 or aa/bb/cc, though also keep in mind that if you have ANY files that don't have numeric prefix, they will load after the numbered files, overriding the settings. This is because depending on your language settings the "lexical sorting" the shell uses sorts numbers first and then may interleave upper and lowercase when sorting in "ascending" order.




                                      Try running printf '%sn' 0..99,A-Z,a-z | sort and printf '%sn' 0..99,A-Z,a-z | LANG=C sort to see whether your current language prints AaBbCc etc or ABC then abc to determine what the best "last" letter prefix to use would be.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 22 '17 at 21:26









                                      dragon788dragon788

                                      250210




                                      250210





















                                          0














                                          To allow any user to execute program as sudo without asking password you can add following line



                                          %sudo ALL=(root) NOPASSWD: /path/to/your/program



                                          in /etc/sudoers



                                          Note that %sudo make it.






                                          share|improve this answer























                                          • While that's one way to accomplish a sudo rule, it doesn't answer the question about why setting the NOPASSWD flag on this rule still resulted in a password prompt. See the accepted answer for an idea why it happened.

                                            – Jeff Schaller
                                            Mar 2 at 17:19











                                          • Thank you for pointing out. @JeffSchaller

                                            – ultimatex
                                            Mar 2 at 17:39















                                          0














                                          To allow any user to execute program as sudo without asking password you can add following line



                                          %sudo ALL=(root) NOPASSWD: /path/to/your/program



                                          in /etc/sudoers



                                          Note that %sudo make it.






                                          share|improve this answer























                                          • While that's one way to accomplish a sudo rule, it doesn't answer the question about why setting the NOPASSWD flag on this rule still resulted in a password prompt. See the accepted answer for an idea why it happened.

                                            – Jeff Schaller
                                            Mar 2 at 17:19











                                          • Thank you for pointing out. @JeffSchaller

                                            – ultimatex
                                            Mar 2 at 17:39













                                          0












                                          0








                                          0







                                          To allow any user to execute program as sudo without asking password you can add following line



                                          %sudo ALL=(root) NOPASSWD: /path/to/your/program



                                          in /etc/sudoers



                                          Note that %sudo make it.






                                          share|improve this answer













                                          To allow any user to execute program as sudo without asking password you can add following line



                                          %sudo ALL=(root) NOPASSWD: /path/to/your/program



                                          in /etc/sudoers



                                          Note that %sudo make it.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Mar 2 at 17:11









                                          ultimatexultimatex

                                          1012




                                          1012












                                          • While that's one way to accomplish a sudo rule, it doesn't answer the question about why setting the NOPASSWD flag on this rule still resulted in a password prompt. See the accepted answer for an idea why it happened.

                                            – Jeff Schaller
                                            Mar 2 at 17:19











                                          • Thank you for pointing out. @JeffSchaller

                                            – ultimatex
                                            Mar 2 at 17:39

















                                          • While that's one way to accomplish a sudo rule, it doesn't answer the question about why setting the NOPASSWD flag on this rule still resulted in a password prompt. See the accepted answer for an idea why it happened.

                                            – Jeff Schaller
                                            Mar 2 at 17:19











                                          • Thank you for pointing out. @JeffSchaller

                                            – ultimatex
                                            Mar 2 at 17:39
















                                          While that's one way to accomplish a sudo rule, it doesn't answer the question about why setting the NOPASSWD flag on this rule still resulted in a password prompt. See the accepted answer for an idea why it happened.

                                          – Jeff Schaller
                                          Mar 2 at 17:19





                                          While that's one way to accomplish a sudo rule, it doesn't answer the question about why setting the NOPASSWD flag on this rule still resulted in a password prompt. See the accepted answer for an idea why it happened.

                                          – Jeff Schaller
                                          Mar 2 at 17:19













                                          Thank you for pointing out. @JeffSchaller

                                          – ultimatex
                                          Mar 2 at 17:39





                                          Thank you for pointing out. @JeffSchaller

                                          – ultimatex
                                          Mar 2 at 17:39











                                          0














                                          The following is for the case where you want to run a command without password only if it has a specific set of options, where a part of the options is variable. AFAIK it is not possible to use variables or value ranges in sudoers declarations, i.e. you can allow access explicitly to command option1 but not command option2 using:



                                          user_name ALL=(root) /usr/bin/command option1



                                          but if the structure is command option1 value1, where value1 can vary, you would need to have explicit sudoers lines for each possible value of value1. Shell script provides a way around it.



                                          This answer was inspired by M. Ahmad Zafar's answer and fixes the security issue there.



                                          1. Create a shell script where you call the command without sudo.

                                          2. Save the script in a root-privileged folder (e.g. /usr/local/bin/), make the file root-owned (e.g. chown root:wheel /usr/local/bin/script_name) with no write access for others (e.g. chmod 755 /usr/local/bin/script_name).


                                          3. Add the exception to sudoers using visudo:



                                            user_name ALL=(root) NOPASSWD: /usr/local/bin/script_name.



                                          4. Run your script sudo script_name.


                                          For example, I want to change display sleep timeout on macOS. This is done using:



                                          sudo pmset displaysleep time_in_minutes



                                          I consider changing the sleep timeout an innocent action that doesn't justify the hassle of password typing, but pmset can do many things and I'd like to keep these other things behind the sudo password.



                                          So I have the following script at /usr/local/bin/ds:



                                          #!/bin/bash
                                          if [ $# -eq 0 ]; then
                                          echo 'To set displaysleep time, run "sudo ds [sleep_time_in_minutes]"'
                                          else
                                          if [[ $1 =~ ^([0-9]|[1-9][0-9]|1[0-7][0-9]|180)$ ]]; then
                                          pmset displaysleep $1
                                          else
                                          echo 'Time must be 0..180, where 0 = never, 1..180 = number of minutes'
                                          fi
                                          fi


                                          At the end of sudoers file I have the following line:



                                          user_name ALL=(root) NOPASSWD: /usr/local/bin/ds



                                          To set the timeout at 3 minutes, I run my script from the ordinary user account user_name:



                                          sudo ds 3



                                          PS Most of my script is input validation, which is not mandatory, so the following would also work:



                                          #!/bin/bash
                                          pmset displaysleep $1





                                          share|improve this answer








                                          New contributor




                                          Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.
























                                            0














                                            The following is for the case where you want to run a command without password only if it has a specific set of options, where a part of the options is variable. AFAIK it is not possible to use variables or value ranges in sudoers declarations, i.e. you can allow access explicitly to command option1 but not command option2 using:



                                            user_name ALL=(root) /usr/bin/command option1



                                            but if the structure is command option1 value1, where value1 can vary, you would need to have explicit sudoers lines for each possible value of value1. Shell script provides a way around it.



                                            This answer was inspired by M. Ahmad Zafar's answer and fixes the security issue there.



                                            1. Create a shell script where you call the command without sudo.

                                            2. Save the script in a root-privileged folder (e.g. /usr/local/bin/), make the file root-owned (e.g. chown root:wheel /usr/local/bin/script_name) with no write access for others (e.g. chmod 755 /usr/local/bin/script_name).


                                            3. Add the exception to sudoers using visudo:



                                              user_name ALL=(root) NOPASSWD: /usr/local/bin/script_name.



                                            4. Run your script sudo script_name.


                                            For example, I want to change display sleep timeout on macOS. This is done using:



                                            sudo pmset displaysleep time_in_minutes



                                            I consider changing the sleep timeout an innocent action that doesn't justify the hassle of password typing, but pmset can do many things and I'd like to keep these other things behind the sudo password.



                                            So I have the following script at /usr/local/bin/ds:



                                            #!/bin/bash
                                            if [ $# -eq 0 ]; then
                                            echo 'To set displaysleep time, run "sudo ds [sleep_time_in_minutes]"'
                                            else
                                            if [[ $1 =~ ^([0-9]|[1-9][0-9]|1[0-7][0-9]|180)$ ]]; then
                                            pmset displaysleep $1
                                            else
                                            echo 'Time must be 0..180, where 0 = never, 1..180 = number of minutes'
                                            fi
                                            fi


                                            At the end of sudoers file I have the following line:



                                            user_name ALL=(root) NOPASSWD: /usr/local/bin/ds



                                            To set the timeout at 3 minutes, I run my script from the ordinary user account user_name:



                                            sudo ds 3



                                            PS Most of my script is input validation, which is not mandatory, so the following would also work:



                                            #!/bin/bash
                                            pmset displaysleep $1





                                            share|improve this answer








                                            New contributor




                                            Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                            Check out our Code of Conduct.






















                                              0












                                              0








                                              0







                                              The following is for the case where you want to run a command without password only if it has a specific set of options, where a part of the options is variable. AFAIK it is not possible to use variables or value ranges in sudoers declarations, i.e. you can allow access explicitly to command option1 but not command option2 using:



                                              user_name ALL=(root) /usr/bin/command option1



                                              but if the structure is command option1 value1, where value1 can vary, you would need to have explicit sudoers lines for each possible value of value1. Shell script provides a way around it.



                                              This answer was inspired by M. Ahmad Zafar's answer and fixes the security issue there.



                                              1. Create a shell script where you call the command without sudo.

                                              2. Save the script in a root-privileged folder (e.g. /usr/local/bin/), make the file root-owned (e.g. chown root:wheel /usr/local/bin/script_name) with no write access for others (e.g. chmod 755 /usr/local/bin/script_name).


                                              3. Add the exception to sudoers using visudo:



                                                user_name ALL=(root) NOPASSWD: /usr/local/bin/script_name.



                                              4. Run your script sudo script_name.


                                              For example, I want to change display sleep timeout on macOS. This is done using:



                                              sudo pmset displaysleep time_in_minutes



                                              I consider changing the sleep timeout an innocent action that doesn't justify the hassle of password typing, but pmset can do many things and I'd like to keep these other things behind the sudo password.



                                              So I have the following script at /usr/local/bin/ds:



                                              #!/bin/bash
                                              if [ $# -eq 0 ]; then
                                              echo 'To set displaysleep time, run "sudo ds [sleep_time_in_minutes]"'
                                              else
                                              if [[ $1 =~ ^([0-9]|[1-9][0-9]|1[0-7][0-9]|180)$ ]]; then
                                              pmset displaysleep $1
                                              else
                                              echo 'Time must be 0..180, where 0 = never, 1..180 = number of minutes'
                                              fi
                                              fi


                                              At the end of sudoers file I have the following line:



                                              user_name ALL=(root) NOPASSWD: /usr/local/bin/ds



                                              To set the timeout at 3 minutes, I run my script from the ordinary user account user_name:



                                              sudo ds 3



                                              PS Most of my script is input validation, which is not mandatory, so the following would also work:



                                              #!/bin/bash
                                              pmset displaysleep $1





                                              share|improve this answer








                                              New contributor




                                              Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.










                                              The following is for the case where you want to run a command without password only if it has a specific set of options, where a part of the options is variable. AFAIK it is not possible to use variables or value ranges in sudoers declarations, i.e. you can allow access explicitly to command option1 but not command option2 using:



                                              user_name ALL=(root) /usr/bin/command option1



                                              but if the structure is command option1 value1, where value1 can vary, you would need to have explicit sudoers lines for each possible value of value1. Shell script provides a way around it.



                                              This answer was inspired by M. Ahmad Zafar's answer and fixes the security issue there.



                                              1. Create a shell script where you call the command without sudo.

                                              2. Save the script in a root-privileged folder (e.g. /usr/local/bin/), make the file root-owned (e.g. chown root:wheel /usr/local/bin/script_name) with no write access for others (e.g. chmod 755 /usr/local/bin/script_name).


                                              3. Add the exception to sudoers using visudo:



                                                user_name ALL=(root) NOPASSWD: /usr/local/bin/script_name.



                                              4. Run your script sudo script_name.


                                              For example, I want to change display sleep timeout on macOS. This is done using:



                                              sudo pmset displaysleep time_in_minutes



                                              I consider changing the sleep timeout an innocent action that doesn't justify the hassle of password typing, but pmset can do many things and I'd like to keep these other things behind the sudo password.



                                              So I have the following script at /usr/local/bin/ds:



                                              #!/bin/bash
                                              if [ $# -eq 0 ]; then
                                              echo 'To set displaysleep time, run "sudo ds [sleep_time_in_minutes]"'
                                              else
                                              if [[ $1 =~ ^([0-9]|[1-9][0-9]|1[0-7][0-9]|180)$ ]]; then
                                              pmset displaysleep $1
                                              else
                                              echo 'Time must be 0..180, where 0 = never, 1..180 = number of minutes'
                                              fi
                                              fi


                                              At the end of sudoers file I have the following line:



                                              user_name ALL=(root) NOPASSWD: /usr/local/bin/ds



                                              To set the timeout at 3 minutes, I run my script from the ordinary user account user_name:



                                              sudo ds 3



                                              PS Most of my script is input validation, which is not mandatory, so the following would also work:



                                              #!/bin/bash
                                              pmset displaysleep $1






                                              share|improve this answer








                                              New contributor




                                              Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.









                                              share|improve this answer



                                              share|improve this answer






                                              New contributor




                                              Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.









                                              answered 2 days ago









                                              Koit SaarevetKoit Saarevet

                                              1




                                              1




                                              New contributor




                                              Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.





                                              New contributor





                                              Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.






                                              Koit Saarevet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.



























                                                  draft saved

                                                  draft discarded
















































                                                  Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                  • 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%2funix.stackexchange.com%2fquestions%2f18830%2fhow-to-run-a-specific-program-as-root-without-a-password-prompt%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

                                                  getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                                                  Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                                                  Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.