Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: help to deal with ssh connection

by vinoth.ree (Monsignor)
on May 18, 2014 at 17:21 UTC ( [id://1086519]=note: print w/replies, xml ) Need Help??


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."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1086519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2026-04-19 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.