It is currently Sat, 05 Dec 2020 13:10:04 GMT



 
Author Message
 Automated password change from within shell script.

Hi,

I want to be able to change user-passwords from withing a shell-script.
I tried the standard passwd program but was unable to redirect the
interactive keyboard driven password change mechanism to read the new
passwords from a file.
Is there some "passwd" program or shell script around that enables you to
supply the new password on the command line ?
We run Solaris 2.4 on multiple SS5's.

Thanks,
Pieter Boeykens
Bayer Antwerpen.
e...@bayant.be



 Sun, 06 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

: Hi,

...

: Is there some "passwd" program or shell script around that enables you to
: supply the new password on the command line ?

What?  On the command line?!?@!  The password would show up in the
output of the w and ps commands, remember, so I doubt it.  Wouldn't
be hard to write one, though.    

: Thanks,
: Pieter Boeykens
: Bayer Antwerpen.
: e...@bayant.be

Andrew

--
                              MVRDOCK
               - QVANTVLA SAPIENTIA REGITVR MVNDVS -

+-------------------------------------------------------------------+
|                    Unix System Administrator                      |
|                    ^^^^^^^^^^^^^^^^^^^^^^^^^                      |
| "You can't hate yourself in the morning if you sleep 'till noon." |
+-------------------------------------------------------------------+



 Sun, 06 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

If you download the "shadow" source package and compile it manually,
then youll find the program chpasswd which does the desire task. The
program reads a pair of username/password from stdin and is even able to
do mass-updates.

Within a shellskript, you can use it like this:

echo $user:$password | chpasswd

--
Michael Keukert, International Sales & Marketing Manager
SCP GmbH, Auf der Hls 120, D-52068 Aachen, Germany
Phone: ++49-241-96830-0
Fax  : ++49-241-96830-50
http://www.scp.de



 Sun, 06 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

No, not so easy! "passwd" is deliberately coded to accept input ONLY
from keyboard. You've got to play some tricks to get around it ;-)

cheers,
wanli



 Tue, 08 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

So why not just use the crypt function call in a small c, perl, ...
program.  This is done fairly easily.  Then all you would have to
do is specify the user names and let the program change the
program change the password.

Here is a little snip-it of code a friend of mine wrote that will
generate a random password for some user.

#
# Rnd_passwd creates a random password for for the new user.
#
sub Rnd_passwd {
   local $rndpass;
   local $thispass;
   local $lttrs;
   local $pwlen, $rndp, $rndp2;
   $pwlen = 8;
   $thispass = ' ' x 8;
   $rndpass  = ' ' x 8;
   $lttrs = "abcdefghjklmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789";
   $puncs = "#!.+-";

   srand(time|$$);
   $rndp2 = int(rand($$));
   srand(time|$rndp2);
   $rndp = int(rand(length($puncs)));
   $thispass=substr($puncs,$rndp,1);
   srand(time|$$);
   for ($i=1; $i< $pwlen; $i++)
     {
      $rndp = int(rand(length($lttrs)));
                substr($thispass,$i,1) = substr($lttrs,$rndp,1);
     }
   $rndp = int(rand(pwlen-2))+1;
   $rndp2 = int(rand(length($puncs)));
   substr($thispass,$rndp,1) = substr($puncs,$rndp2,1);
   $rndpass = crypt("$thispass","$puncs");
   return ($rndpass,$thispass);

Rick

--
----------------------------------------------------------------------
||   Richard Norwood (SGI)      | "We have not inherited the Earth  ||
||   GWIS/Technical Consultant  |  from our ancestors."        ||
||                              |                                   ||
||   Phone:  (301)-572-3296     | "We have only borrowed it from    ||
||   Email:  r...@sgi.com       |  our children."                   ||
||   Beeper: 1-800-792-7933     |         - Ancient Proverb         ||
||   Alpha Pager:               |                                   ||
||     ric...@pager.sgi.com     |                                   ||
----------------------------------------------------------------------



 Tue, 08 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

After staring much too long at the screen Wanli Ma (wa...@isd.canberra.edu.au) wrote:
: > What?  On the command line?!?@!  The password would show up in the
: > output of the w and ps commands, remember, so I doubt it.  Wouldn't
: > be hard to write one, though.
: >

: No, not so easy! "passwd" is deliberately coded to accept input ONLY
: from keyboard. You've got to play some tricks to get around it ;-)

I suppose it's time to mention one word:
        expect
--
Jim Bacon (JB211), SysAdmin          Metropolitan Austin Interactive Network
j...@MAIN.Org      http://www.main.org/~jim        include <std/disclaimer.h>
"You deal with content and humans, I deal with reality."
                                        -- A Sysadmin talking to a Webmaster
-... --- ..-. ....



 Tue, 08 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

Actually, "passwd" accepts it input from the terminal, else how could
it work for a telnet session.  Don Libes' "expect" gets around that
limitation fairly easily!
--
Joseph A. Reuter, Wizard-in-Training, speaking for myself alone
reu...@alaska.dh.trw.com  or   Joseph.Reu...@trw.com
"Olorin I was in my youth in the West that is forgotten."--J. R. R. Tolkien



 Sat, 19 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

: : Is there some "passwd" program or shell script around that enables you to
: : supply the new password on the command line ?

: What?  On the command line?!?@!  The password would show up in the
: output of the w and ps commands, remember, so I doubt it.  Wouldn't
: be hard to write one, though.    

I've actually wrestled with this problem before... In an academic environment,
adding 100 or more students can become a pain...

Unless you directly encrypt the password into the shadow file, I don't believe
that it is possible.

However, to get around the security problem, one could execute such a script
while in single user mode. No one could execute a ps or w to snoop passwords.

and hey, if you do know a way, then please let me know :)

        -Dennis

--------------------------------------------------------------------------
Dennis DiPasquale                                     DiPasqu...@Rowan.EDU
College of Engineering                           Rowan University, NJ, USA
http://www.rowan.edu/~dipasqua                             +1 609.256.4742



 Sun, 20 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

In comp.sys.sun.admin was written by Andrew Pitman <murd...@mis.rowan.edu>:
-> Hi Dennis.  :)

is this public group or what ?

-> Isn't there a way to have a C program rewrite it's *argv[]?
-> I think I remember hearing about something like that.      

not a problem but only /usr/ucb/ps sees that...
--
 Matus "fantomas" Uhlar, sysadmin of one server at SANET Kosice, Slovakia
 E-mail: Matus.Uh...@tuke.sk ; WWW: http://ccsun.tuke.sk/users/uhlar
 And don't forget: I work for SANET, but talk for myself, dude... ;-)



 Mon, 21 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

On 3 Sep 97 21:48:20 GMT, dipas...@sun00.rowan.edu (Dennis DiPasquale)
wrote:

There is a passwd perl script in the Perl Camel book.
This would be easy to modify to accept command line input.

A better idea would be to put your usernames and passwords in a file
and then
        cat file | my_passwd_script

This avoids the paswords showing up on ps and w.

Alvaro.



 Tue, 22 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

you could easily write one using an expect script.

-Fiji



 Fri, 25 Feb 2000 03:00:00 GMT   
 Automated password change from within shell script.

Look at the "expect" package: http://expect.nist.gov/

--
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ~  Frank Pardo   <fr...@pardo.org>    http://www.pardo.org  ~
  ~    "Chi fila ha una camicia e chi non fila ne ha due."    ~
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



 Sat, 13 May 2000 03:00:00 GMT   
 
   [ 12 post ] 

Similar Threads

1. Automated password change from within shell script.

2. Changing the password from within a script

3. shell script within shell script (general question)

4. Change standard output within a shell script

5. Changing directories within a bash shell script

6. Changing user within shell script

7. Change user password using shell script

8. Changing User Passwords in Shell Script


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software