el_grom
el_grom

Reputation: 163

Perl - Which module is the best to do SSH, SFTP with public key authentication on windows

Come back here with another perl + SSH problem.

Here is my situation:

I need to connect from a server A to a server B with SSH. Within this SSH connection, I need to make some SFTP connections beside other commands. Concerning the authentication, I need to use the public key authentication. All of that in a Perl script and both server A and B are windows.

Do you know any perl module matching these constraints?

I tried:

  1. Net::SSH::Any, but the API does not mention the public key authentication
  2. Net::OpenSSH, the API says it's not working on windows
  3. Net::SSH::Perl, the API mentions the usage of the private key. When I tried passing it, it fails (code below). If I tried with Putty, it works.

Extra question: I read that storing the private key (on server A in my case) is not safe at all (and I understand why), is there a way to avoid that?

Code:

my $ssh = Net::SSH::Perl->new("server-ip", identity_files => [ 'path-to-private-key' ], option => ["BatchMode yes"]);
$ssh->login('login');

Upvotes: 3

Views: 2288

Answers (1)

salva
salva

Reputation: 10242

I am the author of Net::OpenSSH and Net::SSH::Any.

Net::SSH::Any does support public key authentication but there are a couple of hidden requirements:

  • The key must be in OpenSSH format (you can use PuTTY companion utilities to convert keys between formats, google for it)
  • A file with the public key is also required and it must be placed at "${path_to_private_key}.pub".

Besides that, over the last couple of months I have been working on improving Net::SSH::Any and on the way fixing lots of important bugs on the underlying Net::SSH2 module and the libssh2 library. If you feel courageous, you may like to try the development version (you will need the git versions of the three packages, Net::SSH::Any, Net::SSH2 and libssh2).

I would really appreciate getting any feedback about it, specially when running under Windows.

Upvotes: 6

Related Questions