Is there a way to automatically prepopulate a password field?

I want to know if there is a way that I can right a script that will su to root and prepopulate the password field?

How do you mean "prepopulate"? Do you mean adding the entries in the passwd file? That is taken care of by the passwd program. You do not need to manually add entries in the /etc/passwd file.

Sorry I should have been a little more clearer.

What I mean is suppose I wanted to write a simple script that would run su (username) and would add to the password field automatically without needing to enter it at the password prompt?

Chris

This is from my manual page on 'passwd'. Yours may not have this option. I believe some versions of passwd are intentionally written so that the password must be entered from the keyboard.

$ man passwd
...
       --stdin
              This  option  is  used  to indicate that passwd should read the new password
              from standard input, which can be a pipe.

Yes there is, but why?
You'd have to store the root passwd in your script, which isn't very secure. You could encrypt it, but then you'll need a passphrase to decrypt it, so a)it defeats your purpose of not typing a passwd or b) encrypted data without a passphrase is as good as ASCII.

You could also use sudo to allow your user access to root commands; that way you don't need to su to root every time you need to do a specific task. Of course, if you allow a user full access, again, not very secure.

On this paticular server root is blocked to every ip but mine and one other. Both trusted,

Ok. I'm not going to lecture you any more on security, so here's one way of doing it with expect:

#!/usr/local/bin/expect --
spawn su -
expect Password:
send myRootPassword\r
expect myPrompt
interact

Once you type exit, both you'll exit root and the script will die and you'll be back to your regular user.