passwordssolarissolaris-10

Solaris/Unix password change in-line


I'm trying to change the root password on Solaris in a single command. So far I've tried:

echo "password" | passwd --stdin root

returns illegal option -- stdin on Solaris.

echo -e "password\npassword" | passwd root

Returns a 'New Password' prompt.

Using Solaris 10 and Bash 3.2.51 for the script.


Solution

    1. You could do this via expect.
    2. You could directly edit the /etc/shadow with sed or perl (of course you have to hash your password before, however as you want to hardcode it in your script you could use a different system, set the password manually copy it in your script and run the script of the target system. Or hash it on your own. is not that hard.
    3. In solaris 11.3 starting with SRU4 there is a passwd -p to directly set the hash of the password. Would at least obfuscate the password by just putting the hash into the commandline.

    But my real answer is: Don't do it ... just don't do it. By setting the root password this way you essentially write a note with pink,blue and green marker around it with the root password in public for everyone who is on the system able to run ps in the moment you set the password. And this don't include the problem of management software putting ps outputs into central repositories and so put this information totally out of control of the system administrator.