Answer the question
In order to leave comments, you need to log in
How can I run a script as a user that has commands that run as root without asking for a password?
I am writing an installer script for an Arch Linux distribution.
1) The script contains commands that must be run on behalf of the user .
2) There are commands in the script that require superuser rights .
I want the script to run continuously. That is, when executing sudo commands, the user was NOT asked for a password and the script continued to work .
What I did : I saved the password from the user (which I added to sudoers in advance), ran the script on behalf of the user, and in it, in commands that require root, I simply attributed
it. It would seem that everything is fine, the crutch works, but that's bad luck.
echo $USER_PASS | sudo -S command
There is one very inconvenient command that I use in the script
makepkg -sri
. The fact is that it does not allow itself to be run as root. But in the process of its execution, it itself invokes sudo, which of course I cannot specify the -S parameter.
What to do in such a situation? No solution? Forget about script continuity?
The script itself (I just started learning BASH this week):
Answer the question
In order to leave comments, you need to log in
What to do in such a situation?
username ALL=(ALL:ALL) NOPASSWD: ALL
sudo -u username command
Will not help the father of Russian democracy?
There has already been a lot of advice here, I will add:
If "one very inconvenient command" calls sudo - then obviously, in its documentation, it should be described how to work in this case.
First, you can add nopasswd to sudoers for a specific command.
Secondly, I'm not sure, but try setting the sticky bit for the program that asks for a password.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question