I need to execute a command which is needed to run as root.
I read some post about using hard-coded passwords in scripts could be insecure, but actually I don’t care because I’m providing root password to users anyway. It’s an stripped system and there’s only 2 users: client and root, so avoid warning me about security issues, Go ahead and give a quick and dirty solution.
For this bash script I need to
get as superuser using su,
then “my command”,
and then logout.
I don’t want the terminal prompt to type the password myself, instead read the password that I’m providing somewhere in script and run the command. It’s a priority to not prompt any input by user.
Alternatively, maybe I could install sudo, but is there any chance to run a command without any prompt of password (editing sudoers or something)?
What about of using expect?
Update: I forgot to say that is also a portable SO, used for USB sticks (maybe later for CDLive too), as you know, in some distros of this kind is provided a root password if users needed. The command mentioned before is a package extensions for some application install, and only root have privilegies to execute such command (I have to say it’s not a apt-get install or rpm command, so don’t worry about this).
If you want a command to be runnable with no password, set that specific command as runnable with no password in your
/etc/sudoersfile (limiting the arguments to only the specific ones you wish to allow, if your use case allows that limitation).This is as simple as setting the
NOPASSWD:flag for the relevant sudoers entry.If you really, really don’t care about security, it could be as simple as this:
(after putting sudo-capable users in the
adminUNIX group)…or, if you did care, you could do something specific:
Note that if these commands will be run with no user present, they also may not have a TTY assigned; in such a case, you must be sure that your
sudoersfile doesn’t contain the (oft-present-by-default) line:…or that the effect of this default is being specifically discarded by the line granting permissions.