Operating System - HP-UX
1826715 Members
2652 Online
109702 Solutions
New Discussion

setting password non-interactively

 
SOLVED
Go to solution
Vijaya Kumar_3
Respected Contributor

setting password non-interactively

Hi

HP-UX 11.00/Non-trusted
using passwd command:

I need to set password no-interactively inside a script for about 100 users, how can i do that?

Thanks
Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
5 REPLIES 5
Vijaya Kumar_3
Respected Contributor

Re: setting password non-interactively

I got it from another thread.

I am sorry.

we need to use either perl or expect.

Thanks
Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
RAC_1
Honored Contributor
Solution

Re: setting password non-interactively

You have one more option.

Check command -
/usr/sam/lbin/usermod.sam
There is no substitute to HARDWORK
Sridhar Bhaskarla
Honored Contributor

Re: setting password non-interactively

Hi Vijay,

If your need is only to change the passwords for 100 users on one system, then you don't need expect or perl->telnet|ssh. You can do it with the following

1. Generate an encrypted string or the password. You can use readily available '/usr/lib/makekey' to generate the passwords. However, this tools requires that the password be of only maximum 8 characters. It takes 10 characters and treats the first 8 chars as password and the last two as salt. For ex., to generate encrypted password for the string 'test1234' you would do

echo "test1234xy" |/usr/lib/makekey
xypACCd55zGKk

It the password is less than 8 chars, then you will need to make it upto 8 chars by adding 'null's. FOr ex., if your password is 'test12' then you would run

echo 'test12\0\0xy' |/usr/lib/makekey

If your password is more than 8 chars, then you will need to write a small c program that uses 'bigcrypt' and generates the encrypted string.

2. Once you generated the encrypted password, then it's a matter of using '/usr/sam/lbin/usermod.sam -p '

You can easily write a script that can do the above.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Rita C Workman
Honored Contributor

Re: setting password non-interactively

I created a dummy user and gave it a password. (newpass value)
We needed to reset a 'bunch' of users at one time and just wanted to use default password for them all. Note that we identified the specific users (they were all caps login-id), you will have to adjust for this.

So, with the help of someone from HP, came up with the following:

#!/bin/sh
#
#
########################
# This script is to mass change
# passwords and set account
# to force user to change p/w
# at next login..
# Written by Sven Liessem HP.com
# and Rita Workman
# May, 2002
#
# YOU MUST FIRST GET THE
# ENCRYPTED PASSWORD VALUE
# FOR NEWPASS VALUE
#
#
# I run this script and output
# to another file & then
# lay file over /etc/passwd
# ex: ./scripts/passwd_mass_chg.sh > /etc/passwd.new
#########################
newpass="d.Cm86XRE3oH6,3..."
cat /etc/passwd | while read line
do
echo $line | grep -q '^[A-Z][A-Z]*:[^:]*,3\.\.\.:'
if [ $? -eq 0 ]
then
usrname=`echo $line | cut -d: -f1`
therest=`echo $line | cut -d: -f 3-`
echo $usrname:$newpass:$therest
else
echo $line
fi
done

Hey if it helps...enjoy
Rita

Steven E. Protter
Exalted Contributor

Re: setting password non-interactively

I has to be perl??

They outlawed shell scripting in your shop?

:-) :-)

Create a little colon delimited textfile, perms 600 that looks like this

user:password

schmobagel:hello1


for user in `awk '{ FS=":"; print $1 }' /root/passwd`
do
password = awk ' ' { FS=":" ;print $2) '

passwd $user << EOF
$password
$password
EOF

done

May need a tweak but its simple. Simpler still if you are using the same password, such as Change1 or something like that. If so I recommend you add code to expire the account if its not used in seven days.

passwd -r file -n $MINDAYS -x $MAXDAYS $user
# should be self evident how to use this.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com