[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passwd command




On Mon, 23 Nov 1998, Mike Almogy wrote:

> Is anyone knows how i can change passwd (or grant new one) to users only

"does anyone know" (sorry, couldn't resist this).

> with one line ?

basically:  ( echo "bla32bla" ; sleep 5; echo "bla32bla" ) | passwd nobody

the '(' and ')' cause the 3 commands (echo, sleep and echo) to be executed
in a sub-shell, so the otuput of ALL 3 of them gets redirected into
'passwd'.

now, why the sleep? apparently, passwd flashes out any pending input
before prompting for the password, thus if you use two consecutive
'echo' commands, the first might get used, but the second will probably
get flushed away (partially of fully).  you may play with the '5'
parameter (like, try '2' or even '1, and see if it still works).

a better method ofcourse would be to check the output of the passwd
command, sending out the command only after it wrote out the prompt. this
can be done with perl, thought i'd gather that 'expect' suites this
better (two-way interaction with external commands in perl requires using
an implicit fork and i/o redirection).

and in any case, be careful - your list of posts recently makes me wonder
if you are realy keeping your system safe enough.

HTH,
guy