in reply to help to deal with ssh connection

You can execute commands on remote host using a Perl script using the Net::SSH::Perl module.

This module allows you to execute a command remotely and receive the STDOUT, STDERR, and exit status of that remote host command.

One big advantage of Net::SSH::Perl over other methods is that you can automate the login process, that way you can write fully automated perl scripts, no console interaction is required in order to authenticate in the remote machine.

#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use Data::Dumper; my $Host = "xxxxxx"; my $User = "xxxxxx"; my $Secret = "xxxxxx"; my $Path="/home/ree"; #Connect my $ssh = Net::SSH::Perl->new($Host); $ssh->login($User, $Secret); # Execute the command my($stdout, $stderr, $exit) = $ssh->cmd("ls -l $Path");

But if you use Net::OpenSSH module, check useful info from this node Problems with Net::OpenSSH


All is well

Replies are listed 'Best First'.
Re^2: help to deal with ssh connection
by mitchreward (Acolyte) on May 18, 2014 at 22:52 UTC

    thanks for your answer, but I'm using net::ssh (not net::ssh::perl neither net::openssh). Is it possible to authenticate with public key and the net::ssh module ?

      Before we go to ssh with public key authentication, correct the typo in your post Re^2: help to deal with ssh connection, its Net::SSH not set:ssh

      You can get the doc for Net::SSH here Net::SSH

      In that doc its been explained how to generate public key and copy that into your remote machine. If you have done those steps, post us what error your script report.


      All is well

        done, I've edited my previous post.

        Regarding the keys, that's already generated and installed properly on both computer.
        Actually I get the error : Permission denied (publickey,password,keyboard-interactive).

        What I can see in the doc is the Net:SSH module is : "You don't (at least not with this module). Use RSA or DSA keys."