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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

su in a script

Status
Not open for further replies.

Patten

Technical User
Aug 22, 2002
106
BE
How can i do a silent su (without having to type on the prompt the password) in a shell script.

I want sth like this:

unix commands (with user1)
su (to user2)
unix commands (with user2)
exit (to user1 back)
unix commands (with user1)

It should be executable from the prompt without having to type in passwords when it starts executing commands with user 2

ps: do i have to use su or su - ?
 
You can use expect with sudo and a script embedded password,
but in all cases embedding passwords , either in readable
memory(variable) or a file is a security problem.
 
i also propose 'ssh' -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Code:
su (go to root)

run script:
Code:
su (to user1)
unix commands (with user1)
exit
su (to user2)
unix commands (with user2)
exit (to user1 back)
su (to user1)
unix commands (with user1)

...

:)
 
jad
I don't have root permissions.
Can I su while giving the password with it? So I don't have to type it in on the prompt while executing my main shellscript?
 
you might want to set up a .rhosts file allowing user1 to rsh as user2 ... then you don't need to su ...

maybe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top