setting initial passwords

2007-12-25 9:19:00

I thank all those sent in their replies, especially Matthew Ball, 'cause

i ended up using his solution.

--Muralinath Pala.

Original Post

-------------

> I'm in the process of creating some 1000+ new users on our system.

> I have a list of initial passwords for these users (each user having

> a unique initial passsword). I already have a script to create the users

> with a null password. The question is, How do i automate the process of

> setting the initial passwords for these users? All my attempts to use

> 'passwd' in the script with input from the list of passwords have been

> futile. May be i'm missing somethings here.

>

> I would appreciate it if someone could help me with this ( shell script

> or C routine). Please email me directly, as i don't have access to this

> mailing list.

>

> Thanks.

***************************************************************************

Solution Summary

----------------

From: Matthew Ball <matthewb@airport.bt.co.uk>

Date: Wed, 31 Jan 1996 18:38:31 GMT

Try this, a little C programme I just knocked up!

Syntax:

   mkpasswd string

It then echoes an encrypted passwd suitable for an /etc/passwd or /etc/shadow

file.

Alternatively

   mkpasswd < file_of_strings > file_of_passwd

encrypt a file of strings into passwords in one go.

----------------mkpasswd.c---------------------------------------------

#include <stdio.h>

#include <string.h>

main(argc,argv)

int argc;

char *argv[];

{

  char line[512],salt[3];

  int i,l;

  salt[2]='\0';

  if(argc == 1) /* No parameters there read from standard input */

  {

    while(gets(line) != NULL)

    {

      l=strlen(line);

      if(l > 2)

      {

        salt[0]=line[2];

        salt[1]=line[1];

        printf("%s\n",crypt(line,salt));

      }

      else

        fprintf(stderr,"Too short [%i] \"%s\"\n",l,line);

    }

  }

  else

  {

    for(i=1;i<argc;i++)

    {

      l=strlen(argv[i]);

      if(l > 2)

      {

        salt[0]=argv[i][2];

        salt[1]=argv[i][1];

        printf("%s\n",crypt(argv[i],salt));

      }

      else

        fprintf(stderr,"Too short [%i] \"%s\"\n",l,argv[i]);

    }

  }

}

--------------------END mkpasswd.c-----------------------------------

This is all based on the crypt sub-routine (man -s 3 crypt).

Hope it helps!

*******************************************************************

Other Replies

-------------

*********************************************************************

From: leclerc@austin.asc.slb.com

Date: Wed, 31 Jan 1996 13:18:42 -0600

use expect : a tcl application which is able to redirect and feed 'tty'

input/output.

There was a paper on USENIX many years ago.

for the location, use archie.

********************************************************************

>From jipping@cs.hope.edu Wed Jan 31 16:02 EST 1996

Date: Wed, 31 Jan 1996 16:08:46 -0500

From: jipping@cs.hope.edu (Mike Jipping)

The "passwd" command wants I/O directly from user and bypasses redirection.

You need a program called "expect" that is designed for this. Expect does

user banter well, and I include below a little password script that works for

us.

**********************************************************************

>From chris@cwi.net Wed Jan 31 16:50 EST 1996

Date: Wed, 31 Jan 1996 16:56:38 -0500

From: Chris Eastman <chris@cwi.net>

the crypt function is used to create the passwd field entry, all you

would have to do is have your program pipe the password to crypt, then

return the results in the form of a variable to be used with your shell

script. I don't currently have the crypt command on this machine, but if

I am not mistaken crypt.c is in the shared libs for libc - I need to

write the same program, mail me again if you still need help and I will

write it up - otherwise send me your solution. :)

*********************************************************************

>From zh@cc.bellcore.com Wed Jan 31 17:04 EST 1996

Date: Wed, 31 Jan 1996 17:11:06 -0500 (EST)

From: Zhiyi Huang <zh@cc.bellcore.com>

For Solaris 2.x:

  passwd -d -f -x 180 -n 0 -w 14 $user

will do it. Where $user is the new user's login name.

********************************************************************

Comments

Got something to say?

You must be logged in to post a comment.