rastoboy has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Brothers,

I must be candid and admit I'm not sure if I'm phrasing my question well, or if it even makes any sense at all.

Basically I'm looking for a way to safely make changes on remote servers.

For example, if I wanted to safely automate changing a user's password on my local machine, my first instinct is to search cpan for a perl module to use, such as Unix::PasswdFile, because I know that coders who are more experienced and skilled than I have "worked all the kinks out", and I don't want to reinvent the wheel.

However, I need to do this sort of thing remotely on multiple machines now. I've about decided that Net::OpenSSH appears to be the most stable and predictable way of interacting with my remote servers, but unfortunately, installing Unix::PasswdFile on the remote machine and executing a script I upload is not really tenable (and involves the same issues in any case--cpan is not always foolproof :-) ).

I guess what I'm wondering is if there is a generalized system for treating the remote machine as if it was local? Or a technique for handling the situation when complex, interactive behaviors are required? In the password example I've given, I'd really rather avoid reading/writing to pipes while executing /usr/bin/passwd on the remote machine, as a blocking issue could make the machine inaccessible, for example. Does that make any sense?

Replies are listed 'Best First'.
Re: Using local perl modules on remote SSH
by salva (Canon) on Feb 09, 2011 at 09:30 UTC
    as a blocking issue could make the machine inaccessible

    Not really, the password command will not update the passwords database until the interactive dialog finishes, so the worst thing that can happen is ending with an unchanged password.

    Anyway, check also IPC::PerlSSH. Its documentation says that it allows to transfer and run Perl modules, scripts or code on the remote machine without installed anything there.

    Another option, would be to make, anyhow, sshfs work over an SSH channel in the reverse direction (mounting a client share into the server). Update: I have added that feature to Net::OpenSSH but it is highly experimental, and requires a patched version of sshfs. It is available from the GitHub repository on the sshfs branch.

Re: Using local perl modules on remote SSH
by ikegami (Patriarch) on Feb 09, 2011 at 05:41 UTC

    installing Unix::PasswdFile on the remote machine and executing a script I upload is not really tenable

    If the Perl on the remote machine is compatible to the one on the local machine, then it's just a question of using scp to transfer Unix::PasswdFile's blib dir (or an archive of it).

Re: Using local perl modules on remote SSH
by hsinclai (Deacon) on Feb 09, 2011 at 15:12 UTC
    Is your actual task changing user passwords on remote boxes?

    Unless you have to do other tasks /locally/ on the remote machines, it seems overengineering to install modules, etc etc, just in order to do many password changes.

    Consider doing your work (generating passwords with crypt ?) on the controlling side and using Net::OpenSSH to connect to the remote boxes and execute the 'usermod' program (I'm assuming linux/solaris) on the remote host which will save you a lot of coding work, is native to the system in question's configured passwd encryption formats and just lets you change a password with a single command.

      Thanks All, some very interesting and helpful ideas!