Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

su to root in a script

Status
Not open for further replies.

witt

Programmer
May 29, 2003
4
US
I need to su to the root account in a script (ksh). How do you pass root password in the script.

Thank
 
CAN'T [sig]<p> Tony ... aka chgwhat<br><a href=mailto:tony_b@technologist.com>tony_b@technologist.com</a><br><a href= > </a><br>When in doubt,,, Power out...[/sig]
 
Try writing an expect script and a read() call. Although this is not secure in any way. [sig]<p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
[/sig]
 
You may also want to check out the &quot;sudo&quot; program. [sig]<p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
[/sig]
 
The sudo pacakge is the way to go -- very reliable and widely used. [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
Hi

How do u use sudo to su to root without having to provide a password.
My username is userA who is in group system

My sudoers file is as follows:


root ALL=(ALL) ALL
tso910 ALL=(ALL) ALL

When I type:

/usr/local/bin/sudo su - root

I still get prompted for a password and I would like to go straight in

Any help greatly appreciated
 
sorry about that

Was meant to be posting a new subject not replying to your message

Apologies
 
No way!!!
It's impossible to give a password to &quot;su&quot; instead of stdin.
No redirrection is feasable and for a very good security reason, if root password is written in a non crypted file everybody can read it.
Use sudo for tasks like this
 
In reply to Mdraja:
<<How do u use sudo to su to root without having to provide a password.
My username is userA who is in group system>>

Edit your /etc/sudoers file and create a Cmnd_Alias stanza containing the commands you'd like userA to run. Something like this:

Cmnd_Alias KILLCMND = /usr/bin/kill

Now under your "user privilege specification" for userA pust something like this:

userA {hostname} = NOPASSWD: KILLCMND

Here hostname would be a specific host if you have multiple hosts, other wise just leave the hostname out and it would read:
userA NOPASSWD: KILLCMND

That should work for you.

An infinite number of monkey typing at an infinite number of keyboards will eventually populate the internet.
 
Run the script AS root and su to your user when required.

I take it you have the root password ?

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top