Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5948529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:07:13+00:00 2026-05-22T17:07:13+00:00

I have a simple perl test script which uses Net::SSH2 , and I’m having

  • 0

I have a simple perl test script which uses Net::SSH2, and I’m having trouble getting it to work with public key authentication.

Note: After reading a couple of replies, I realise that I should mention that I created the script to help narrow down a problem I was having with another application that uses Net::SSH2. It’s therefore not possible for me to switch to an alternative package such as Net::OpenSSH or Net::OpenSSH::Compat::SSH2.

Note Update: As salva pointed out, Net::OpenSSH::Compat::SSH2 can be used without having to patch the original application.

Here’s the code:

use strict;
use warnings;
use 5.10.0;

use Net::SSH2;

my $ssh2 = Net::SSH2->new();
my $auth;

if ( $ssh2->connect('hostname') ) {

    $auth = $ssh2->auth_publickey(
       'username',
       '/home/mike/.ssh/id_rsa.pub',
       '/home/mike/.ssh/id_rsa',
       'password'
    );  
}   

if ($auth && $ssh2->auth_ok) {
    say 'Success';
} else {
    say join ', ', $ssh2->error;
}  

I have been generating key pairs using ssh-keygen on Ubuntu:

ssh-keygen -t rsa
ssh-copy-id user@server
ssh user@server

The above works correctly – I can SSH to the server.

When I run the Perl code, I get the following error when using a password protected key:

-16, LIBSSH2_ERROR_FILE, Unable to initialize private key from file

If I try with a non-password protected key, it works correctly.

I have the following libraries installed:

Net::SSH2         0.35

libssh2-1         1.2.2-1
libssh2-1-dev     1.2.2-1
ssh               1:5.3p1-3ubuntu6
openssh-server    1:5.3p1-3ubuntu6
openssh-client    1:5.3p1-3ubuntu6
openssl           0.9.8k-7ubuntu8.6
libssl-dev        0.9.8k-7ubuntu8.6

The plot thickens

If I remove libssh2-1 and libssh2-1-dev, I get an error, as expected:

Can't load '/usr/local/lib/perl/5.10.1/auto/Net/SSH2/SSH2.so'

If I then build libssh2 from source, I am unable to reinstall Net::SSH2, as it can’t find the development headers. However, if I reinstall libssh2-1 and libssh2-1-dev and then build and install libssh2 from source, it works.

Does that mean that the build of libssh2-1-dev on Ubuntu 10.04 is at fault? If so, how do I install libssh2 from source and correctly install Net::SSH2, without requiring libssh2-1-dev. I presume that the build from source is overwriting or overriding the Ubuntu package.

UPDATE

As noted in Daniel Stenberg’s reply, the Ubuntu 10.04 package is now a little out of date (version 1.2.2, compared with the latest stable build at 1.2.8). Installing libssh2 from source ‘over the top’ of the Ubuntu package solves the problem. However, this feels messy to me. How can I remove the Ubuntu package, install libssh2 from source, and still build Net::SSH2 — how do I tell Net::SSH2 where to find the libssh2 development headers?

UPDATE 2

salva came to the rescue again, and showed how the Net::SSH2 installer can be configured with lib and include directories, so that it may be used with the source install of libssh2. Thanks salva! Note that instead of patching Makefile.PL, it’s possible to just override the $lib and $inc variables at the top of Makefile.PL. I wasn’t aware of this until I looked at salva’s patch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:07:14+00:00Added an answer on May 22, 2026 at 5:07 pm

    I have been able to successfully log into a server using a pass-phrase protected key with Net::SSH2 from the the Ubuntu 11.04 libnet-ssh2-perl package.

    Anyway, consider using Net::OpenSSH or Net::OpenSSH::Compat::SSH2 instead of Net::SSH2.

    Update: Net::OpenSSH::Compat::SSH2 tries to be a replacement for Net::SSH2. There is no need to patch the application in order to try it:

    perl -MNet::OpenSSH::Compat=Net::SSH2 yor_app.pl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Perl script which runs as a Linux daemon using an
Trying to get a simple test perl script working. Have the following files/folder structure
I have a simple perl script that uses DBD::Oracle to run a query and
I have a Perl script where I maintain a very simple cache using a
I have simple Perl/CGI scripts based web server which is mainly used to display
I have learned Perl and PHP.So I want to do simple real time project
i have something like: #!/usr/bin/perl use strict; use warnings; use CGI::Simple; use DBI; my
I have simple SSIS package which reads data from flat file and insert into
I'm having issues with getting DBI's IBM DB2 driver to work with mod_perl. My
I have a list of arguments to pass into a Perl script, using ARGV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.