I have the root password in one of my scripts and I want to launch another script which requires root permission from this script. How can I use the root password which I have so that I do not have to ask the user the root password which launching 2nd script.

link|improve this question
if this is a programming question shouldn't this be on stackoverflow? – rzlines Aug 20 '09 at 8:00
@rzlines,: Administrative bash scripts are not really 'programming', it may be a better fit for ServerFault, or UnixSE... but really it should be just fine where it is. – TechZilla May 23 at 20:04
feedback

1 Answer

There's a lot of security implications in this, but let's get right to the best way to handle this.

Don't use the root password directly. Use sudo to run the scripts. Sudo is installed by default on Ubuntu and is available on almost all popular Linux distributions in the package repositories. Once sudo is installed, you'll want to edit /etc/sudoers.

su -
visudo
# add something like the following:
Cmnd_Alias SCRIPT=/path/to/script1
script_user ALL=NOPASSWD: SCRIPT

Thus script_user can run the first script as root through sudo, which would then launch the other script as root. For more information about the sudoers file, see the sudoers(5) man page on your system.

But do your scripts absolutely have to run as root? Most times this isn't required at all, but is done out of convenience.

link|improve this answer
1  
Don't you mean script_user ALL=NOPASSWD: SCRIPT ? – grawity Aug 20 '09 at 12:40
@grawity thanks, thats what I get for posting at 2am or whatever it was ;) – jtimberman Aug 20 '09 at 13:41
feedback

Your Answer

 
or
required, but never shown