Wednesday 25 September 2013

Resetting Solaris passwords without the passwd command

We've all been there, you can't get on to a Solaris server because someones lost the password, or you want to deploy a set of users with predefined passwords. Here's how you get around not having a useful tool like chpasswd found elsewhere...

For basic passwords out of the box, you can do something like this to set the password to that well known Jumpstart password, 'newroot':-

perl -pi -e "s/^root:.?\:/root:boajrOmu7GRmY\:/" /etc/shadow 

Sadly for the stronger options in Solaris 9 and onwards you need to be able to handle $ in there which I'm not enough of a Perl nut to figure a way around. The fix i've gone for is primitive, but it works.

cat /etc/shadow | sed 's/^root:.[^:]*:/root:$5$062qyog8$Vny5sE9NEDnam1rB4Dn6ObMABoBFd2R02HpCMlKRQn4:/' > /etc/shadow  

...or if you have the gnu command line tools:-

gsed -i 's/^root:.[^:]*:/root:$5$062qyog8$Vny5sE9NEDnam1rB4Dn6ObMABoBFd2R02HpCMlKRQn4:/' /etc/shadow  

Easiest way is to copy and paste from another server where you know it... failing that there are generators on google and bits of perl/python to do it.

No comments: