Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password assigning under AIX5.1

Status
Not open for further replies.

onyxia

Programmer
Oct 6, 2005
2
DE
Hi all,

I've got a question about password generating / password assigning (under AIX 5.1)
I'd like to assign a predefined password to an optional user.
The password has been created before by a password generator and I don't know how to assign this password automatically to a special user.
"passwd" and "useradd" seem not to have a possibility to set passwords by an argument or something similar . The script I expect should create automatically the password and assign it to a user. There shouldn't be any input by prompt.

Someone can help me?
 
Thank you p5wizard! This will certainly help me!
 
Hi,

Here is a more concise perl function I used to generate passwords for aix 4.3.3 and aix 5.2 : say gen_crypted.pl

Code:
#!/usr/bin/perl
#--------------------------------------------
# input : path/to/passwordfile login password
#--------------------------------------------
if ( $#ARGV < 2 ){
        print "Usage : $0 <output file> login password\n";
        print "output file = file containing crypted password\n";
        die;
}
use POSIX;
$ENV{'TZ'} = "GMT";
#--------------
# get arguments
#--------------
$ofile=@ARGV[0];
$login=@ARGV[1];
$pass=@ARGV[2];

#---------------------------------------
# generate 2 random ASCII chars for salt
#---------------------------------------
$hz= int(rand()*100) + 26;
$c1=chr($hz);
while ( $c1 !~ "[./0-9A-Za-z]"  ) {
        $hz= int(rand()*100) + 26;
        $c1=chr($hz);
}
$hz= int(rand()*100) + 26;
$c2=chr($hz);
while ( $c2 !~ "[./0-9A-Za-z]"  ) {
        $hz= int(rand()*100) + 26;
        $c2=chr($hz);
}

$salt="$c1$c2";

#-------------------
# crypt the password
#-------------------
$passcrypt = crypt($pass,$salt) ;
#-------------------
# get epoch date
#-------------------
$epoch = POSIX::time() ;
#---------------------------------------------
# write a password stanza to given output file
#---------------------------------------------
open (OUT, ">>$ofile") || die "cant open $ofile: $!.\n";
print OUT<<EOF;
$login:
        password = $passcrypt
        lastupdate = $epoch
        flags =

EOF
exit 0

How to use it in a shell script :

Code:
#perl gen_crypted.pl try.passwd user123 mypass

The generated stanza is the same as /etc/security/passwd

Code:
#cat try.passwd

user123:
        password = U2AuRvAzhEx3I
        lastupdate = 1128690322
        flags =
                 
#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top