I am writing a Perl script that needs to transfer files between computers using scp. I know about public key authentication, but I need the script to be fully automated, so I can’t visit the machines to set up the keys before the script is run.
Is there any way to either pass the password to scp from the Perl script or set up the keys from within the perl script?
This script will be run as part of a build script that also reimages the hard drive I need to run the script on. So I can’t be there to set up keys every time the project is built.
You could use the Perl Expect module, see an example at Well House consultants’ forum.
Its documentation has a telnet example which is easily changed for SSH.
Net::SSH::Expect is another Perl module to do exactly what you want. I haven’t used this one previously, though.