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

Hi, Monks, good day.

I wonder anybody tried Net::SFTP::Foreign with priv key with passphrase and also password before?

Here is a good thread about how to support both key and password authentication. salva gave a lot of explanations.But in this case, no passphrase was mentioned. Does Net::SFTP::Foreign support identity file and user password?

In my case, if I pass passphrase in the hash, it will give me error: Invalid option 'password' or bad combination of options at ..../MySFTP.pm line .... Here is the code sample:

my $sftp = Net::SFTP::Foreign->new( $sftp_host, more => [ '-o', "IdentityFile=$ssh_key_path", '-o', 'PreferredAuthentications=keyboard-interactive,pas +sword,publickey', '-vvv' ], user => $sftp_user, password => $sftp_password, passphrase => $sftp_passphrase, timeout => 10, port => $port, stderr_fh => $my_err );

I can manually log into remote server with passphrase and password typed in when being asked.

Thank you very much.

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign does not support both passphrase and password?
by salva (Canon) on Oct 13, 2015 at 16:59 UTC
    Net::SFTP::Foreign is not able to authenticate the user using both a password and a passphrase protected key.

    But you can handle the authentication yourself using some tool like Expect and then pass Net::SFTP::Foreign just the open connection. See the sample script passwd_conn.pl.

Re: Net::SFTP::Foreign does not support both passphrase and password?
by RonW (Parson) on Oct 14, 2015 at 18:33 UTC

    Since the pass phrase is used to protect the identity file, you could avoid the need for it by setting up the identity file to not require a pass phrase. (This will not affect the server because the server never "sees" the pass phrase.)

    If that is not acceptable, then if your objective to avoid having to type in the pass phrase each time you run your Perl program, then you could use ssh-agent so you would only need to type in your phrase phase once, when you log in.

    If you really need to have the Perl program enter the pass phrase, it might be easier to automate ssh-agent/ssh-add than ssh itself (because Net::SFTP::Foreign is using ssh).

A reply falls below the community's threshold of quality. You may see it by logging in.