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;
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
add a comment
|
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
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
add a comment
|
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
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
command-line bash permissions scripts sudo
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
add a comment
|
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
add a comment
|
1 Answer
1
active
oldest
votes
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:
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.
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) ALLThis will override anything. So put your line in the last lines of the sudoers file.
Using this method you can actually remove the sudo inside the file since all the script will run as root.
1
Thanks for your answer. Removingshfrom command solved it!
– FooBar
Sep 25 at 13:25
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
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.
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) ALLThis will override anything. So put your line in the last lines of the sudoers file.
Using this method you can actually remove the sudo inside the file since all the script will run as root.
1
Thanks for your answer. Removingshfrom command solved it!
– FooBar
Sep 25 at 13:25
add a comment
|
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:
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.
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) ALLThis will override anything. So put your line in the last lines of the sudoers file.
Using this method you can actually remove the sudo inside the file since all the script will run as root.
1
Thanks for your answer. Removingshfrom command solved it!
– FooBar
Sep 25 at 13:25
add a comment
|
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:
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.
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) ALLThis will override anything. So put your line in the last lines of the sudoers file.
Using this method you can actually remove the sudo inside the file since all the script will run as root.
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:
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.
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) ALLThis will override anything. So put your line in the last lines of the sudoers file.
Using this method you can actually remove the sudo inside the file since all the script will run as root.
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. Removingshfrom command solved it!
– FooBar
Sep 25 at 13:25
add a comment
|
1
Thanks for your answer. Removingshfrom 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
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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