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

Automate su in script

Status
Not open for further replies.

maxcrook

Programmer
Jan 25, 2001
210
GB
Im trying to set up a script that logs in as another user however when i put the su command in the password is always prompted for.

I need to login as the user sample.

Is there a way round the prompt for a password ?
 
You need to get the other user to edit the .rhosts file in their home directory.

The .rhost file should contain an entry

localhost yourname



 
There isnt a .rhosts file in the users home directory.
Is there an option,flag that can be used with the su command to look at a file with the password in it ?
 
Max, not as far as I'm aware.

However, if the .rhosts file doesn't exist, get the user to create it. HTH.
 
Are you logging into another machine, or the same machine? Are you logging in with "rlogin" or "telnet"?

If you are *not* running as root and do an "su", you will *always* be prompted for a password.

Bill.
 
If you run a script as root, use this:
su - sample -c &quot;<commands you want to run separated by semicolon>&quot;

AS the others have said, this won't work unless you run it as root.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top