Thursday, April 02, 2009

Solaris Password change one liner

I searched for a while this morning looking for a quick and simple answer to a very simple question: "How can I set a password non-interactively for a user on Solaris 10 ?".

Under Linux this job is very simple (use the '-p' option to useradd) but for Solaris I found ridiculous posts about admins using multi-line PERL scripts or even expect scripts to change a password. Expect?! EXPECT? I didn't even realise people still used such things ?!

Any how... here is a simple PERL one liner for updating the shadow file:

perl -pe 's/^USERNAME:.*?\:/USERNAME:NEWPASS\:/' /etc/shadow > /tmp/shadow.tmp && mv /tmp/shadow.tmp /etc/shadow


Note: This oneliner requires the password to be crypt()'d first. This can be done easily as a one liner in PERL:

[bisscuitt@asimov ~]$ perl -e "print crypt($ARGV[0], substr(rand(date),2));" PLAINTEXTPASSWORD
50kq0KhJnHwU2


Hope this helps someone.

Have Fun,
BiSScuiTT

No comments: