Operating System - HP-UX
1848604 Members
6490 Online
104033 Solutions
New Discussion

Re: changing password for users

 
Aravindh Rajaram
Honored Contributor

changing password for users

I want to change password for users without having to confirm the password. It would be nice if i can set the password for a user using a stdin from a file...is this possible?

Or is there any script available where i can give the username and new password as parameters and then the password gets set.
6 REPLIES 6
Nagashankarp
Frequent Advisor

Re: changing password for users

use this script
Note: this can be used to change the password of a userid to a standard new password, replace the string "Jusilasdfjjl" with the standard new password.

I am sure you know how to get the new password string.

Also you can have the usserid replaced by an argument.

#!/bin/ksh
cat passwd | grep -v userid >> pass.tmp1
cat passwd | grep userid >> pass.tmp2
PASS1=`cat pass.tmp2 | cut -d ":" -f2`
PASS2=`Jusilasdfjjl`
sed 's/$PASS1/$PASS2/g' pass.tmp2 > TMPFILE && mv TMPFILE pass.tmp2
cat pass.tmp2 >> pass.tmp1
mv pass.tmp1 passwd

Best of luck
Javed Khan_1
Valued Contributor

Re: changing password for users

Hi,
You may try by installing expect on your system . Once you have expect installed on system you can user
#autopasswd username new passwd
Regards,
Javed
Never Give Up
Doug O'Leary
Honored Contributor

Re: changing password for users

Hey;

The psaswd command, like telnet, does not accept redirected stdin. As mentioned, expect is a program that's designed to circumvent this issue by using psuedo ttys.

Unfortunately, expect's programming syntax leaves ALOT to be desired.

On the bright side, though, perl has an expect module so you have all the power of expect with the sytnaxt of perl. They make an absolutely outstanding combination.

I don't have a current perl script to change user's passwords. I do have one to change root's password that relies on ssh access to root using public key authentication (the only way to allow direct root access).

I can post it if you're familiar with perl; otherwise, it wouldn't be worth your time.

Let me know.

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Aravindh Rajaram
Honored Contributor

Re: changing password for users

Hi all,

Thanks for your inputs. I have few more questions:

Nagashankarp: After foloowing the procedure that you suggested, the passwords are not getting into effect...Should I do something more?

Javed Khan: Do you know if expect is part of HP-UX MC-OE bundle? Also, is there a installer available from HP?

Doug O'Leary: I wanted to know how I can make use of the "expect" in PERL. Any thoughts? Also, you can send me the script to reset root password. That would be very handy for me.

Thanks,
AMicSys
Doug O'Leary
Honored Contributor

Re: changing password for users

Hey;

As for the first suggestion, I'd be very careful about automatically replacing the password file. One misstep and your password file is gone meaning no access to the system. I don't see anything wrong with the logic, but it's generally a risky proposition.

Expect does not come with HPUX; however, you can download a precompiled binary in depot format from http://hpux.cs.utah.edu/hppd/hpux/Tcl/expect-5.43/

The script, mypwd, is attached. As I said previously, this iteration assumes an ability to directly login to root via public key authentication (the only way to allow direct root access). It can certainly be expanded to either ssh in as a normal user, then sudo su - password, or any number of other possibilities.

The expect module doesn't come with the perl installation either. It has to be installed. There's a fairly significant number of prerequisite modules that must be installed as well some of which have to be compiled. I've had mixed results getting the expect module working on HP systems (w/GNU compiler installed) which is one of the reasons most of my expect work is done on Linux boxes.

perl -MCPAN -e shell
cpan> install Expect

should do the trick for you. The CPAN module will install and compile all the modules needed to install Expect.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Nagashankarp
Frequent Advisor

Re: changing password for users

I agree with Doug, An extra step needs to be added to backup passwd file

Amicsys : If your using NIS,i think you should do a ypmake

Also make user the PASS2 variable has the right string, this you can get by setting a temp user to the required password and using the password string from it.