Allow a shell script containing sudo to runHow do I run a 'sudo' command inside a script?How to allow a command to be executed for a particular user without password with sudoers file?Visudo not working for specified filesWhy does sudoers only allow me to set NOPASSWD for ALL?Allow nopasswd sudo for specific userHow to add flags and/or arguments to a command in the 'sudoers' fileWhat is the most secure way to use sudo permissions in a script?Ubuntu Unity 16.10 'sudo: no tty present and no askpass program specified'Editing sudoers.d to allow www-data run a specific fileUbuntu 18.04 - sudo: no tty present and no askpass program specified

Replying an email

Why should you have travel insurance?

Why doesn't knowledge of how magic works break magic in this world?

How do I get a stuck gas canister (for hiking/camping) out of a stainless steel mug?

Besides TGV train, how can I travel around France from Paris area during a strike?

Does the production of a Tesla battery produce as much CO2 as driving 200,000 km?

Is using Swiss Francs (CHF) cheaper than Euros (EUR) in Switzerland?

Bash globbing that matches all files except those with a specific extension, that works on filenames that include dot characters

Key takeaways in German in a presentation

Is it valid to use std::transform with std::back_inserter?

How do planes maintain constant speeds at cruise altitudes?

Elliptic Integrals: Mathematica and Gradshteyn and Ryzhik

Is it safe to drink the water from the fountains found all over the older parts of Rome?

What are the ethical implications of lying to get into a course?

Home rebuild and demolish

I have to make an API where I can return orders (product name) placed by a customer using customer Id?

How do you get to this trap position?

What are the downsides of being a debt-free country (no national debt?

Is rotating a pawn so that it faces a different direction and then moves in that direction technically permitted according to the 2018 FIDE Laws?

Are unitarily equivalent permutation matrices permutation similar?

Is "lasts until dispelled" a duration?

New manager unapproved PTO my old manager approved, because of a conference at the same time that's now a "condition of my employment here"

C - random password generator

The Formula of Explicit Runge-Kutta Fourteen order



Allow a shell script containing sudo to run


How do I run a 'sudo' command inside a script?How to allow a command to be executed for a particular user without password with sudoers file?Visudo not working for specified filesWhy does sudoers only allow me to set NOPASSWD for ALL?Allow nopasswd sudo for specific userHow to add flags and/or arguments to a command in the 'sudoers' fileWhat is the most secure way to use sudo permissions in a script?Ubuntu Unity 16.10 'sudo: no tty present and no askpass program specified'Editing sudoers.d to allow www-data run a specific fileUbuntu 18.04 - sudo: no tty present and no askpass program specified






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0


















I am trying to allow a specific user to run a specific .sh file that has a sudo chmod inside of it.



I have followed this guide: How to allow a command to be executed for a particular user without password with sudoers file?



My sudoers file now looks like this:



the_user ALL=(ALL:ALL) NOPASSWD: /var/www/html/storage/fix_cache_permissions.sh


However, when I run the command:



sh /var/www/html/storage/fix_cache_permissions.sh


it dies with this error:



sudo: no tty present and no askpass program specified


Update



I tried both having sudo inside the .sh file and outside when running the command. Both results in the same error message.










share|improve this question






















  • 2





    Possible duplicate of How do I run a 'sudo' command inside a script?

    – Melebius
    Sep 25 at 13:01











  • thanks @Melebius but that results in the same error message

    – FooBar
    Sep 25 at 13:11











  • @Melebius George had it right.

    – FooBar
    Sep 25 at 13:27

















0


















I am trying to allow a specific user to run a specific .sh file that has a sudo chmod inside of it.



I have followed this guide: How to allow a command to be executed for a particular user without password with sudoers file?



My sudoers file now looks like this:



the_user ALL=(ALL:ALL) NOPASSWD: /var/www/html/storage/fix_cache_permissions.sh


However, when I run the command:



sh /var/www/html/storage/fix_cache_permissions.sh


it dies with this error:



sudo: no tty present and no askpass program specified


Update



I tried both having sudo inside the .sh file and outside when running the command. Both results in the same error message.










share|improve this question






















  • 2





    Possible duplicate of How do I run a 'sudo' command inside a script?

    – Melebius
    Sep 25 at 13:01











  • thanks @Melebius but that results in the same error message

    – FooBar
    Sep 25 at 13:11











  • @Melebius George had it right.

    – FooBar
    Sep 25 at 13:27













0













0









0








I am trying to allow a specific user to run a specific .sh file that has a sudo chmod inside of it.



I have followed this guide: How to allow a command to be executed for a particular user without password with sudoers file?



My sudoers file now looks like this:



the_user ALL=(ALL:ALL) NOPASSWD: /var/www/html/storage/fix_cache_permissions.sh


However, when I run the command:



sh /var/www/html/storage/fix_cache_permissions.sh


it dies with this error:



sudo: no tty present and no askpass program specified


Update



I tried both having sudo inside the .sh file and outside when running the command. Both results in the same error message.










share|improve this question
















I am trying to allow a specific user to run a specific .sh file that has a sudo chmod inside of it.



I have followed this guide: How to allow a command to be executed for a particular user without password with sudoers file?



My sudoers file now looks like this:



the_user ALL=(ALL:ALL) NOPASSWD: /var/www/html/storage/fix_cache_permissions.sh


However, when I run the command:



sh /var/www/html/storage/fix_cache_permissions.sh


it dies with this error:



sudo: no tty present and no askpass program specified


Update



I tried both having sudo inside the .sh file and outside when running the command. Both results in the same error message.







command-line bash permissions scripts sudo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 30 at 6:10









Melebius

7,9965 gold badges30 silver badges55 bronze badges




7,9965 gold badges30 silver badges55 bronze badges










asked Sep 25 at 12:31









FooBarFooBar

1033 bronze badges




1033 bronze badges










  • 2





    Possible duplicate of How do I run a 'sudo' command inside a script?

    – Melebius
    Sep 25 at 13:01











  • thanks @Melebius but that results in the same error message

    – FooBar
    Sep 25 at 13:11











  • @Melebius George had it right.

    – FooBar
    Sep 25 at 13:27












  • 2





    Possible duplicate of How do I run a 'sudo' command inside a script?

    – Melebius
    Sep 25 at 13:01











  • thanks @Melebius but that results in the same error message

    – FooBar
    Sep 25 at 13:11











  • @Melebius George had it right.

    – FooBar
    Sep 25 at 13:27







2




2





Possible duplicate of How do I run a 'sudo' command inside a script?

– Melebius
Sep 25 at 13:01





Possible duplicate of How do I run a 'sudo' command inside a script?

– Melebius
Sep 25 at 13:01













thanks @Melebius but that results in the same error message

– FooBar
Sep 25 at 13:11





thanks @Melebius but that results in the same error message

– FooBar
Sep 25 at 13:11













@Melebius George had it right.

– FooBar
Sep 25 at 13:27





@Melebius George had it right.

– FooBar
Sep 25 at 13:27










1 Answer
1






active

oldest

votes


















3



















You are missing something here. The sudoers file refers to the sudo command. By running sh yourprogram.sh you are not using the sudo command, you are using the sh one which in turn will use the sudo afterwards.



So the correct way to accomplish what you want is by marking the script as executable so that the user then can write



sudo /var/www/html/storage/fix_cache_permissions.sh


and this will not ask for the password.



Notes:



  1. Since you are getting this error that means that you are not running the command from some sort of terminal. If it doesn't ask for password then I think that this will not be a problem.



  2. The order of the commands in the sudoers file is important and they override one another. Meaning that if you write you command and afterwards in the file there is something like this:



    %sudo ALL=(ALL:ALL) ALL


    This will override anything. So put your line in the last lines of the sudoers file.



  3. Using this method you can actually remove the sudo inside the file since all the script will run as root.






share|improve this answer






















  • 1





    Thanks for your answer. Removing sh from command solved it!

    – FooBar
    Sep 25 at 13:25












Your Answer








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

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

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1176575%2fallow-a-shell-script-containing-sudo-to-run%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown


























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3



















You are missing something here. The sudoers file refers to the sudo command. By running sh yourprogram.sh you are not using the sudo command, you are using the sh one which in turn will use the sudo afterwards.



So the correct way to accomplish what you want is by marking the script as executable so that the user then can write



sudo /var/www/html/storage/fix_cache_permissions.sh


and this will not ask for the password.



Notes:



  1. Since you are getting this error that means that you are not running the command from some sort of terminal. If it doesn't ask for password then I think that this will not be a problem.



  2. The order of the commands in the sudoers file is important and they override one another. Meaning that if you write you command and afterwards in the file there is something like this:



    %sudo ALL=(ALL:ALL) ALL


    This will override anything. So put your line in the last lines of the sudoers file.



  3. Using this method you can actually remove the sudo inside the file since all the script will run as root.






share|improve this answer






















  • 1





    Thanks for your answer. Removing sh from command solved it!

    – FooBar
    Sep 25 at 13:25















3



















You are missing something here. The sudoers file refers to the sudo command. By running sh yourprogram.sh you are not using the sudo command, you are using the sh one which in turn will use the sudo afterwards.



So the correct way to accomplish what you want is by marking the script as executable so that the user then can write



sudo /var/www/html/storage/fix_cache_permissions.sh


and this will not ask for the password.



Notes:



  1. Since you are getting this error that means that you are not running the command from some sort of terminal. If it doesn't ask for password then I think that this will not be a problem.



  2. The order of the commands in the sudoers file is important and they override one another. Meaning that if you write you command and afterwards in the file there is something like this:



    %sudo ALL=(ALL:ALL) ALL


    This will override anything. So put your line in the last lines of the sudoers file.



  3. Using this method you can actually remove the sudo inside the file since all the script will run as root.






share|improve this answer






















  • 1





    Thanks for your answer. Removing sh from command solved it!

    – FooBar
    Sep 25 at 13:25













3















3











3









You are missing something here. The sudoers file refers to the sudo command. By running sh yourprogram.sh you are not using the sudo command, you are using the sh one which in turn will use the sudo afterwards.



So the correct way to accomplish what you want is by marking the script as executable so that the user then can write



sudo /var/www/html/storage/fix_cache_permissions.sh


and this will not ask for the password.



Notes:



  1. Since you are getting this error that means that you are not running the command from some sort of terminal. If it doesn't ask for password then I think that this will not be a problem.



  2. The order of the commands in the sudoers file is important and they override one another. Meaning that if you write you command and afterwards in the file there is something like this:



    %sudo ALL=(ALL:ALL) ALL


    This will override anything. So put your line in the last lines of the sudoers file.



  3. Using this method you can actually remove the sudo inside the file since all the script will run as root.






share|improve this answer
















You are missing something here. The sudoers file refers to the sudo command. By running sh yourprogram.sh you are not using the sudo command, you are using the sh one which in turn will use the sudo afterwards.



So the correct way to accomplish what you want is by marking the script as executable so that the user then can write



sudo /var/www/html/storage/fix_cache_permissions.sh


and this will not ask for the password.



Notes:



  1. Since you are getting this error that means that you are not running the command from some sort of terminal. If it doesn't ask for password then I think that this will not be a problem.



  2. The order of the commands in the sudoers file is important and they override one another. Meaning that if you write you command and afterwards in the file there is something like this:



    %sudo ALL=(ALL:ALL) ALL


    This will override anything. So put your line in the last lines of the sudoers file.



  3. Using this method you can actually remove the sudo inside the file since all the script will run as root.







share|improve this answer















share|improve this answer




share|improve this answer








edited Sep 25 at 13:16









Melebius

7,9965 gold badges30 silver badges55 bronze badges




7,9965 gold badges30 silver badges55 bronze badges










answered Sep 25 at 13:11









VGe0rgeVGe0rge

1462 bronze badges




1462 bronze badges










  • 1





    Thanks for your answer. Removing sh from command solved it!

    – FooBar
    Sep 25 at 13:25












  • 1





    Thanks for your answer. Removing sh from command solved it!

    – FooBar
    Sep 25 at 13:25







1




1





Thanks for your answer. Removing sh from command solved it!

– FooBar
Sep 25 at 13:25





Thanks for your answer. Removing sh from command solved it!

– FooBar
Sep 25 at 13:25


















draft saved

draft discarded















































Thanks for contributing an answer to Ask Ubuntu!


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

But avoid


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

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

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




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1176575%2fallow-a-shell-script-containing-sudo-to-run%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

Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

How to get a smooth, uniform ParametricPlot of a 2D Region?How to plot a complicated Region?How to exclude a region from ParametricPlotHow discretize a region placing vertices on a specific non-uniform gridHow to transform a Plot or a ParametricPlot into a RegionHow can I get a smooth plot of a bounded region?Smooth ParametricPlot3D with RegionFunction?Smooth border of a region ParametricPlotSmooth region boundarySmooth region plot from list of pointsGet minimum y of a certain x in a region

Genealogie vun de Merowenger Vum Merowech bis zum Chilperich I. | Navigatiounsmenü