See perlfunc:crypt which has sample code to do exactly what you want. I have used it and it does work.

I would recommend you look into ssh forced commands if you are going to litter (pass-phrase less) keys to roots account around the place (or keys with the pass-phrase embedded in the script). At least that way if someone Ownz the box with the key they can only run the command you allow, although being able to reset passwords is bad enough! Make sure the forced command can only reset the password for allowed accounts- allow by uid range for example. Turn taint mode on for your forced command as well (-wT). Definately do NOT allow roots password to be reset this way! :)

I have used perl with open2 /open3 to the system ssh to send data across the network, open2/3 allows you to talk to stdin/stdout at the same time and passed parameters aren't visible from a local ps. Works well and you don't have to keep two versions of ssh (system & perls) up to date with security fixes.

I still think it is a bad idea though, it sounds like what you really need is NIS or LDAP. Your script then only needs admin privilege to NIS/LDAP and not to root.

Hope this helps

--
my $chainsaw = 'Perl';


In reply to Re: Testing A users's unix password with perl by greenFox
in thread Testing A users's unix password with perl by cfreak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.