When I execute this from command line, I get prompted for joe's password (which is what I want):

ssh -t 'scp joe@ /tmp'

When I try to run the same command from a perl script, it just hangs there (with no prompt):

`ssh -t 'scp joe\@ /tmp'`;

How can I make this work from a Perl script?

Note: No, I cannot use key-based authentication for this.


You could use Expect. See https://stackoverflow.com/a/1366802

(and the Expect module FAQ on this topic http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod#I_want_to_automate_password_entry_for_su/ssh/scp/rsh/... )


You could use Perl's Net::SCP for this, which would be the cleanest (all-perl, no external command calls) solution.

Or you could do as Andrew suggests and use Expect (which is probably quicker).

Or you could fork(), exec(), and waitpid() (letting your scp command have the terminal your Perl script is running from so it can get passwords from you, which is a nice old-school Unix-y approach, but way more work than I'd be willing to do personally).



I had the exact same kind of issues some time ago.

The reason it hangs is because ssh spawns a terminal for the password input. Perl can can not catch this terminal (for reason). "Password" string is never seen by perl.

It's better to use the libs ( Net::SSH2 libs or something similar).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.