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

Bonjour,

I am trying to sync two servers using a perl script. I want this script to run without intervention (so I can set it up as a nightly cron task).

The sysadmin has already poked holes between the two machines so VPN is not required (the machines are not in the same network). And so currently I am required to put in a password to do an scp between them.

My question for the perl monks, is how to wait for Server1 to return a password request, have the perl script on Client1 return the password?

I have tried varriations on  <STDIN> but because the stdin is coming from the shell, not the user, I haven't been able to read it.

Replies are listed 'Best First'.
Re: Syncing Servers using Perl
by Fletch (Bishop) on Jun 26, 2008 at 13:48 UTC

    This isn't a Perl question, it's an ssh question. Create an identity on the originating box, put the key in the authorized_keys file on the destination box, make sure the originating box can get to the key by means of ssh-agent or the like. If you're still having problems STFW for any of the umpteen bazillion howtos that are out there.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      The ssh keys were setup, and Client1 is in Server1's authorized keys file.

      However the organization still requires a passphrase for .ssh/id_rsa, leading me back to my original question. How to automate this with perl.

        So, as I said: set up ssh-agent on the box with the identity, let that hold the passphrase guarded key for you, and it'll just work (presuming said ssh-agent is running, which may require some form of manual intervention if/when it restarts to unlock the identity for it). It's still not a Perl problem.

        If you're dead set on making it a Perl problem you'd want to look into something like Expect and let that drive your scp, but then you'd need to embed the plaintext passphrase somewhere in code and you've taken two steps back security-wise.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

        Remove that passphrase from .ssh/id_rsa. If the passphrase is stored in a script anyway it doesn't provide additional security.

        BTW if you want to synchronize files one way, use rsync. If you want it two way, use unison - very cool tool.