Issue
I am writing a simple shell script which requires a root privilege. Using the terminal if you type sudo su
and you write the password it works definitely.
I want to pass the password to the script file and then pass it to the system to become root ex:
pass= $1
navigateToRoot($pass)
Solution
A better approach would be to :
chmod +s yourfile
chown root yourfile
By setting the setuid
bit, the file will execute as root (owner) without having to store or pass the root password.
Make sure nobody else can modify the script
chmod o-w yourfile
SEE COMMENTS:
SETUID does not work on Shell scripts so this answer is INVALID.
Answered By - koma