tags:

views:

841

answers:

2

I am using Net::SSH::Perl to execute a command on a remote server as follows:

use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);

But when I execute the above script, a password prompt comes again. Meaning the password I supplied in $pass is not taken to establish the ssh connection. Why is this? Any idea how I can overcome this? I give below the debug info:

serv1: Reading configuration data /root/.ssh/config
serv1: Reading configuration data /etc/ssh_config
serv1: Allocated local port 1023.
serv1: Connecting to 15.154.59.63, port 22.
serv1: Remote protocol version 1.99, remote software version OpenSSH_4.2
serv1: Net::SSH::Perl Version 1.34, protocol version 1.5.
serv1: No compat match: OpenSSH_4.2.
serv1: Connection established.
serv1: Waiting for server public key.
serv1: Received server public key (768 bits) and host key (1024 bits).
serv1: Host '15.154.59.63' is known and matches the host key.
serv1: Encryption type: DES3
serv1: Sent encrypted session key.
serv1: Received encryption confirmation.
serv1: RSA authentication failed: Can't load public key.
serv1: Doing challenge response authentication.
Password:

The password prompt should not be coming right, given that I have already supplied the password in $pass variable?

UPDATE(Based on the comments received):

I tried the following:

my $ssh = Net::SSH::Perl->new($host, debug =>1, identity_files => []);

Now, I don't get the message "RSA authentication failed: " but still the password prompt appears. I give below the debug info:

serv1: Allocated local port 1023. 
serv1: Connecting to 15.154.59.63, port 22. 
serv1: Remote protocol version 1.99, remote software version OpenSSH_4.2 
serv1: Net::SSH::Perl Version 1.34, protocol version 1.5. 
serv1: No compat match: OpenSSH_4.2. kf-linux-dm3: Connection established. 
serv1: Waiting for server public key. 
serv1: Received server public key (768 bits) and host key (1024 bits).
serv1: Host '15.154.59.63' is known and matches the host key.
serv1: Encryption type: DES3 
serv1: Sent encrypted session key.
serv1: Received encryption confirmation. 
serv1: Doing challenge response authentication. 
Password:

Could someone enlighten me?

+5  A: 

This line in your errors:

serv1: RSA authentication failed: Can't load public key.

tells me that your program is trying to do automatic logins, which is not what you want to do when you need a password to log in.

Check the Perl/ssh documentation:

identity_files

A list of RSA/DSA identity files to be used in RSA/DSA authentication. The value of this argument should be a reference to an array of strings, each string identifying the location of an identity file. Each identity file will be tested against the server until the client finds one that authenticates successfully.

If you don't provide this, RSA authentication defaults to using $ENV{HOME}/.ssh/identity, and DSA authentication defaults to $ENV{HOME}/.ssh/id_dsa.

You might try setting identity_files to an empty array, to see if that forces it to use your supplied password; or you could go ahead and set up public key authentication like in the link above.

Mark Rushakoff
Setting identity_files to an empty array did not help :( The password prompt still comes up. If I give a path for the rsa key file I get the following error: "Can't use string ("/root/.ssh/id_rsa.pub") as an ARRAY ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Auth/RSA.pm line 40." Any idea why this is happening?
Ninja
@Ninja: Make sure you are supplying a *reference* to an array, not just an array.
Adam Bellaire
@Adam: I am passing only a reference and it's not working. I give below a snippet of my code:@arr = ("");my $ssh = Net::SSH::Perl->new($host, debug =>1, identity_files => \@arr);If I set identity_files to an empty array as suggested by Mark, I get the same message "RSA authentication failed: Can't load public key." and then the password prompt comes. Someone pl. help me.
Ninja
@arr = ("") is not an emtpy array! use [] instead of \@arr.
innaM
@Manni: I tried the following: my $ssh = Net::SSH::Perl->new($host, debug =>1, identity_files => []); Now, I don't get the message "RSA authentication failed: " but still the password prompt appears :'(
Ninja
I give below the debug info:kf-linux-dm3: Allocated local port 1023.kf-linux-dm3: Connecting to 15.154.59.63, port 22.kf-linux-dm3: Remote protocol version 1.99, remote software version OpenSSH_4.2kf-linux-dm3: Net::SSH::Perl Version 1.34, protocol version 1.5.kf-linux-dm3: No compat match: OpenSSH_4.2.kf-linux-dm3: Connection established.kf-linux-dm3: Waiting for server public key.kf-linux-dm3: Received server public key (768 bits) and host key (1024 bits).kf-linux-dm3: Host '15.154.59.63' is known and matches the host key.kf-linux-dm3: Encryption type: DES3
Ninja
kf-linux-dm3: Sent encrypted session key.kf-linux-dm3: Received encryption confirmation.kf-linux-dm3: Doing challenge response authentication.Password:
Ninja
Please add the updated information to your original question :)
brian d foy
@Brian: Updated the question as per ur advice
Ninja
It's failing RSA and proceeding to the next authentication method, so I'm afraid this is barking up the wrong tree...
derobert
A: 

serv1: Doing challenge response authentication.

That's your key line. SSH actually has multiple types of password-like authentication. One of them is strait password authentication (controlled by the PasswordAuthentication option in /etc/sshd_config), I suspect that is what the $pass you sent is for. Another one is challenge-response authentication, where the server sends one or more challenges, and you are expected to reply with the correct responses. Ref and Spec.

So, technically, ssh isn't asking you for a password. Its asking you for a reply to an arbitrary challenge from the server, and that challenge just happens to be "Password: ".

Possibly, it'll work if you use Net::SSH::Perl::KeyboardInt explicitly?

Of course, you really ought to set up RSA public key authentication.

derobert