Derwynd's Weblog

Derwynd's Weblog

Add multiple Users with the same passwd

#!/usr/bin/perl -w

use strict;
use Crypt::PasswdMD5;
# This will ask you for a password once all users will have the same passwd
print “Enter Password: “;
chomp ( my $Passwd = );
$cryptedPasswd = unix_md5_crypt($Passwd, $salt);

# Please create a file /root/username.txt that has all usenames
open(USERFILE, “< /root/username.txt”) || die “Cannot open username file: $!”;
my @users = < USERFILE >;
@users = sort(@users);

# Starting for loop to add users

foreach my $u (@users){
print “$u”;

my $cryptPasswd = “”;
my $salt = rand(99);

system(”useradd -m -d /home/$username $username”);
system(”usermod -p ‘$cryptedPasswd’ $username”);

print “Username is $u, using password hash $cryptedPasswd\n\n”;
close (USERFILE);

November 10, 2008 - Posted by | Uncategorized

Sorry, the comment form is closed at this time.

%d bloggers like this: