Mizzter Back Mizzter Back - 6 months ago 47
Perl Question

Permission denied at ssh.pl line 17 - $ssh->login($user, $password);

I am trying to ssh into a machine and run a command called

mounted
using a perl script.

I keep getting the error:

Permission denied at ssh.pl line 17


Line 17:

$ssh->login($user, $password);


Can anyone help me understand why?

Here's my complete script:

#!/usr/local/bin/perl -w

use strict;
use warnings;
require Net::SSH::Perl;

#declare our login vars...

my $user = "root";
my $password = "";
my $server = "beccles";

#Setup our SSH Connection...
my $ssh = Net::SSH::Perl->new($server,port=>22,protocol=>2, debug => 1);

#Initiate out conneciton to the server...
$ssh->login($user, $password);

# Declare our variable for the request...
my $mounts;
my $name;

# Run our SSH Command and retrieve the output...
($mounts) = $ssh->cmd(`mounted`);
($name) = $ssh->cmd("uname -n");

# Print Output
chomp $name;
#print "\n$mounts\n";

exit 0;


And here's the output I get after I debug the ssh connection:

calver: Remote protocol version 2.0, remote software version OpenSSH_5.3
calver: Net::SSH::Perl Version 1.37, protocol version 2.0.
calver: No compat match: OpenSSH_5.3
calver: Connection established.
calver: Sent key-exchange init (KEXINIT), wait response.
calver: Algorithms, c->s: 3des-cbc hmac-sha1 none
calver: Algorithms, s->c: 3des-cbc hmac-sha1 none
calver: Entering Diffie-Hellman Group 1 key exchange.
calver: Sent DH public key, waiting for reply.
calver: Received host key, type 'ssh-dss'.
calver: Host 'beccles' is known and matches the host key.
calver: Computing shared secret key.
calver: Verifying server signature.
calver: Waiting for NEWKEYS message.
calver: Send NEWKEYS.
calver: Enabling encryption/MAC/compression.
calver: Sending request for user-authentication service.
calver: Service accepted: ssh-userauth.
calver: Trying empty user-authentication request.
calver: Authentication methods that can continue: publickey,gssapi-keyex,gssapi-
with-mic,keyboard-interactive.
calver: Next method to try is publickey.
calver: Publickey: testing agent key '/u/blh/.ssh/blh_git'
calver: Authentication methods that can continue: publickey,gssapi-keyex,gssapi-
with-mic,keyboard-interactive.
calver: Next method to try is publickey.
Permission denied at ssh.pl line 17


Appreciate any help, if any more information need is needed, please ask me.

Thanks :)

Bao Bao
Answer

So to have an official answer from the comment of AKHolland and from the the answer of Arthur Ulfeldt to his own question :

Use keys and define manually your key file location :

@KEYFILE = ("/root/.ssh/id_rsa");
$ssh = Net::SSH::Perl->new($host, debug=>1, identity_files=>\@KEYFILE)