2
I have a bash script running as user
, a user account with no evaluated privileges. The machine has a second account admin
which has sudo privileges. There is no root password set.
The script knows the account password for admin
. How do I escalate the script up to root
?
sudo -S
only handles the case of escalation using your current account's password, such as admin
to root
, but user
is unprivileged, so this won't work.
su admin
works but provides no way to take a password from STDIN.
To rephrase, how can I achieve the below programmatically?
$ su admin
Password: ******
$ sudo command
Password: ******
To preempt comments: Yes, I know storing passwords in a shell script is bad practice. It's part of an overall solution that is even messier. – Bardi Harborow – 2016-01-22T14:36:29.730
Can you add
user
to the sudoers file? – Rocket Hazmat – 2016-01-22T14:47:07.423@Rocket, That would require root access, which is what I'm trying to get in the first place. This is for bulk deployment of an install script, otherwise I would just do it manually. – Bardi Harborow – 2016-01-22T14:49:11.270
Is there is no
root
password set, wouldsu root
(or justsu
) work? – Rocket Hazmat – 2016-01-22T14:54:58.063@Rocket, there is no root password set. Also,
su
password entry can't be done programmatically. – Bardi Harborow – 2016-01-22T14:57:06.117(That should've said
If there...
), but the point was, since is there noroot
password, wouldn'tsu root
not ask for a password and possibly just work? – Rocket Hazmat – 2016-01-22T15:04:03.700@Rocket, login is denied to password-less accounts, which is the entire point behind Ubuntu not having root passwords. – Bardi Harborow – 2016-01-22T15:06:08.920
Ah! Darn it. I didn't realize that. Sorry :) – Rocket Hazmat – 2016-01-22T15:08:11.897