Change unix password oneliner

Posted by Frodo Larik Fri, 02 Mar 2007 11:11:00 GMT

I tried using expect for changing passwords from a script, but expect sometimes works, sometimes not, at least in my case. So I came up with the following oneliner, as root do the following:

 usermod -p `perl -e 'print crypt('mysupersecretpassword',rand(99));'` goofy 

where mysupersecretpassword is the password you want to use and goofy is the user where you want to change the password for.