Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Setting password from a shell script possible?
@ 1995-12-19  5:00 Malcolm Dunnett
  1995-12-21  5:00 ` JONQC
  0 siblings, 1 reply; 5+ messages in thread
From: Malcolm Dunnett @ 1995-12-19  5:00 UTC (permalink / raw)



Is there a program which will allow me to set a password from
within a script ( ie not prompt from the terminal but read the
password string from the script file ).

I'm trying to write a procedure to do a "bulk create" of accounts
(for setting up accounts for CSci classes). I've figured out how to
get the adduser portion to take its input from a script, but it appears
that regardless of what I do the passwd program always reads from the
terminal.

Do I need to reinvent the passwd program, has someone else already done
so, or is there a way to get passwd to do what I want.

adv(Thanks)ance

-- 
=============================================================================
Malcolm Dunnett    Malaspina University-College     Email: dunnett@mala.bc.ca
Computer Services  Nanaimo, B.C. CANADA V9R 5S5       Tel: (604)755-8738



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting password from a shell script possible?
  1995-12-19  5:00 Setting password from a shell script possible? Malcolm Dunnett
@ 1995-12-21  5:00 ` JONQC
  1995-12-21  5:00   ` Malcolm Dunnett
  1995-12-24  5:00   ` Richard Warkentin
  0 siblings, 2 replies; 5+ messages in thread
From: JONQC @ 1995-12-21  5:00 UTC (permalink / raw)


> I'm trying to write a procedure to do a "bulk create" of accounts
> (for setting up accounts for CSci classes). I've figured out how to
> get the adduser portion to take its input from a script, but it appears
> that regardless of what I do the passwd program always reads from the
> terminal.
 
We had the same problem.  At the beginning of every semester, we need to
put up bulk accounts for new students.  The answer to your problems is
the 'expect' program that is mentioned in the OSF FAQ; 'expect' can
"talk" to 'passwd'.
 
The quickest way to go is:  Copy the 'expect' program from the
OSF/1 Freeware disc, modify the 'adduser' script to ask for the
password (which you've probably done already), and then add a line to
'adduser' to let 'expect' do the rest:
 
                setpass ${USER} ${PASSWD}
 
where the 'setpass' script contains the following:
 
#!/usr/local/bin/expect
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect {*quit):}
send p\r
expect {*password:}
send $password\r
expect {*password:}
send $password\r
expect eof
 
NOTE: The FAQ file says that lines 2 & 3 should read "index" instead of
"lindex".  However, the current copy of 'expect' that we downloaded from
ftp.cme.nist.gov (you also need to download 'tcl' if you're going to
make 'expect' from scratch) requires "lindex".  I don't know whether the
version on the Freeware disc uses "index" or "lindex" but that's easy to
find out.
 
FYI:  We usually set the initial password to the student's social
security number.  If you're running C2 security (you probably should
be), you can force them to change their initial password right away by
pre-expiring it.  To do this, add the following 2 lines to 'adduser'-
 
#Delete 'u_succhg' entry in auth file to pre-expire the password
ed -s "${AUTHDIR}/${USER}" < /usr/sbin/adduser.ed_commands
 
Where the file 'adduser.ed_commands' contains the following 3 lines-
 
1,$s/u_succhg#[0-9]*://
w
q
 
Admittedly, I'm still kind of a novice Unix user so maybe someone on
the Net can figure out how to accomplish the pre-expiration all on one
line that doesn't require a second input file but for now, this works.
 
Hope this helps.
 
Jon Leong
Systems Manager
Queens College
City University of New York



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting password from a shell script possible?
  1995-12-21  5:00 ` JONQC
@ 1995-12-21  5:00   ` Malcolm Dunnett
  1995-12-24  5:00   ` Richard Warkentin
  1 sibling, 0 replies; 5+ messages in thread
From: Malcolm Dunnett @ 1995-12-21  5:00 UTC (permalink / raw)


In article <95355.204430JONQC@CUNYVM.CUNY.EDU>, 
   <JONQC@CUNYVM.CUNY.EDU> writes:
>  
> We had the same problem.  At the beginning of every semester, we need to
> put up bulk accounts for new students.  The answer to your problems is
> the 'expect' program that is mentioned in the OSF FAQ; 'expect' can
> "talk" to 'passwd'.
>  

    Thanks for the suggestion. One other person also suggested using
expect.

    I decided to write a program that takes the cleartext
password as a command argument and outputs the encryted password. I 
modified adduser to feed this into an environment variable and then
"echo" the password into the /etc/passwd file along with all the
other information. I haven't put everything together yet, but this
approach seems to work quite well ( if there's a flaw in this
method I'd sure appreciate someone pointing it out ).

-- 
=============================================================================
Malcolm Dunnett    Malaspina University-College     Email: dunnett@mala.bc.ca
Computer Services  Nanaimo, B.C. CANADA V9R 5S5       Tel: (604)755-8738



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting password from a shell script possible?
  1995-12-21  5:00 ` JONQC
  1995-12-21  5:00   ` Malcolm Dunnett
@ 1995-12-24  5:00   ` Richard Warkentin
  1995-12-27  5:00     ` PAUL D. CHAPIN
  1 sibling, 1 reply; 5+ messages in thread
From: Richard Warkentin @ 1995-12-24  5:00 UTC (permalink / raw)


<JONQC@CUNYVM.CUNY.EDU> wrote:

>> I'm trying to write a procedure to do a "bulk create" of accounts
>> (for setting up accounts for CSci classes). I've figured out how to
>> get the adduser portion to take its input from a script, but it appears
>> that regardless of what I do the passwd program always reads from the
>> terminal.
> 
>We had the same problem.  At the beginning of every semester, we need to
>put up bulk accounts for new students.  The answer to your problems is
>the 'expect' program that is mentioned in the OSF FAQ; 'expect' can
>"talk" to 'passwd'.
> 
>The quickest way to go is:  Copy the 'expect' program from the
>OSF/1 Freeware disc, modify the 'adduser' script to ask for the
>password (which you've probably done already), and then add a line to
>'adduser' to let 'expect' do the rest:
> 
>                setpass ${USER} ${PASSWD}
> 
>where the 'setpass' script contains the following:
> 
>#!/usr/local/bin/expect
>set password [lindex $argv 1]
>spawn passwd [lindex $argv 0]
>expect {*quit):}
>send p\r
>expect {*password:}
>send $password\r
>expect {*password:}
>send $password\r
>expect eof
> 
>NOTE: The FAQ file says that lines 2 & 3 should read "index" instead of
>"lindex".  However, the current copy of 'expect' that we downloaded from
>ftp.cme.nist.gov (you also need to download 'tcl' if you're going to
>make 'expect' from scratch) requires "lindex".  I don't know whether the
>version on the Freeware disc uses "index" or "lindex" but that's easy to
>find out.
> 
>FYI:  We usually set the initial password to the student's social
>security number.  If you're running C2 security (you probably should
>be), you can force them to change their initial password right away by
>pre-expiring it.  To do this, add the following 2 lines to 'adduser'-
> 
>#Delete 'u_succhg' entry in auth file to pre-expire the password
>ed -s "${AUTHDIR}/${USER}" < /usr/sbin/adduser.ed_commands
> 
>Where the file 'adduser.ed_commands' contains the following 3 lines-
> 
>1,$s/u_succhg#[0-9]*://
>w
>q
> 
>Admittedly, I'm still kind of a novice Unix user so maybe someone on
>the Net can figure out how to accomplish the pre-expiration all on one
>line that doesn't require a second input file but for now, this works.
> 
>Hope this helps.
> 
>Jon Leong
>Systems Manager
>Queens College
>City University of New York





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting password from a shell script possible?
  1995-12-24  5:00   ` Richard Warkentin
@ 1995-12-27  5:00     ` PAUL D. CHAPIN
  0 siblings, 0 replies; 5+ messages in thread
From: PAUL D. CHAPIN @ 1995-12-27  5:00 UTC (permalink / raw)


Richard Warkentin (rdw@hooked.net) wrote:

: >                setpass ${USER} ${PASSWD}
: > 
Potential problem here is that is somebody does the right ps command
while this is happening, they get to see the username and password
being set up.  There are a couple of ways of handling this including
disabling ps or going down to single user mode.  I've set it up to put
the information in a temporary file and then invoke expect using the
command file rather than command line arguments.

--

Paul Chapin
Unix Systems Manager
Amherst College




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1995-12-27  5:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-12-19  5:00 Setting password from a shell script possible? Malcolm Dunnett
1995-12-21  5:00 ` JONQC
1995-12-21  5:00   ` Malcolm Dunnett
1995-12-24  5:00   ` Richard Warkentin
1995-12-27  5:00     ` PAUL D. CHAPIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox