On Sat, 14 Jul 2001, Chris G Haravata wrote:
> how can i generate the password of all 1157 users in one sweep using their
> usernames as their initial passwords? i have no time to learn perl or
> somesuch languages. can u please help me? u have a script hidden somewhere
> maybe? please...
> -----------------------
try this quick fix. you first set it as executable by setting it
chmod 755 initpasswd.pl
then download the module Crypt::MD5 from CPAN.org, and install it.
then you could run it by (as root of course)
cat /etc/shadow | initpasswd.pl > shadow.new
then the file shadow.new would be the mangled shadow file. Just don't
forget to backup the original /etc/shadow before overwriting it.
hth,
-Mark
#!/usr/local/bin/perl -w
use Crypt::PasswdMD5;
while (<STDIN>) {
# remove trailing new line
chomp;
# split the shadow entry
my ($name, $passwd, $others) = split (':', $_, 3);
# generate the salt
my $salt = &MakeSalt();
# encrypt the passwd using md5
$encrypted = unix_md5_crypt ($name, $salt);
# print the mangled entry to stdout
print "$name\:$encrypted\:$others\n";
}
exit 0;
sub MakeSalt () {
# it's up to if you would like to create random salt
my $salt = "f^7gH";
return $salt;
}