Page 1 of 1

Passwords in Linux scripts?

Posted: Tue Jun 05, 2018 7:07 pm
by Roland
I would need to run "sudo su" in a script (.sh), but how can I include the password it needs? (No need to worry about security, the script will not launch nuclear weapons... ; )

Re: Passwords in Linux scripts?

Posted: Wed Jun 06, 2018 7:19 am
by xeno74
What do you think about this?

sudo visudo

Code: Select all

username ALL=(ALL) NOPASSWD: ALL
Where username is the user who executes the script.

Re: Passwords in Linux scripts?

Posted: Wed Jun 06, 2018 1:19 pm
by Roland
xeno74 wrote:What do you think about this?

sudo visudo

Code: Select all

username ALL=(ALL) NOPASSWD: ALL
Where username is the user who executes the script.
Thanks for the tip! Unfortunately, it works only partially... If I open a Term window, I can now use 'sudo su' without password. But the script where I have 'sudo su' on the first line still doesn't work, except from 'root'. Is there a way to get some output from a script, error messages etc.?

Re: Passwords in Linux scripts?

Posted: Wed Jun 06, 2018 2:56 pm
by xeno74
Why sudo su? You can execute your script with sudo.

Re: Passwords in Linux scripts?

Posted: Wed Jun 06, 2018 8:56 pm
by Roland
xeno74 wrote:Why sudo su? You can execute your script with sudo.
When I first tested the individual commands for the script in a terminal, one of them needed that I use "sudo su". Plain "sudo" was not able to run it. So I thought I have to have 'sudo su' as the first command in the script!

But only after reading your comment above I understood that you speak about a different, "two-layer" approach, where the primary script is run via an auxiliary script with "sudo script_name". That indeed works and solved the problem - thank you !-)