N
N
nobody way2020-02-01 23:41:11
linux
nobody way, 2020-02-01 23:41:11

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):

spoiler
https://github.com/Mogekoff/alma.sh/blob/master/al...

Answer the question

In order to leave comments, you need to log in

4 answer(s)
J
jcmvbkbc, 2020-02-02
@Mogekoff

What to do in such a situation?

Add the user who runs this script to /etc/sudoers with the NOPASSWD flag. Remove crutches:
username ALL=(ALL:ALL) NOPASSWD: ALL

V
Vadim Priluzkiy, 2020-02-02
@Oxyd

sudo -u username command
Will not help the father of Russian democracy?

K
Karpion, 2020-02-02
@Karpion

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.

R
Roman Sokolov, 2020-02-03
@jimquery

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 question

Ask a Question

731 491 924 answers to any question