in reply to Re: Net::SSH2::Channel with exec, reads 0 bytes on suse while works fine on ubuntu
in thread Net::SSH2::Channel with exec, reads 0 bytes on suse while works fine on ubuntu

I run on windows too using cygwin. And I am using Net::SSH2 because it is threadsafe, and I need to use threads.
  • Comment on Re^2: Net::SSH2::Channel with exec, reads 0 bytes on suse while works fine on ubuntu

Replies are listed 'Best First'.
Re^3: Net::SSH2::Channel with exec, reads 0 bytes on suse while works fine on ubuntu
by Anonymous Monk on Apr 28, 2011 at 15:11 UTC
    Here is the code I use under cygwin or linux redhat
    — # connect $ssh2->connect($remote_server) or die "\nERROR02 - Unable to connect H +ost $@ \n"; ($code, $error_name, $error_string) = $ssh2->error(); if ($code ne 0) { &log("error001","code = $code"); &log("error002","error_name = $error_name"); &log("error003","error_string = $error_string"); } if ($ssh_pattern eq '/passphrase/') { # authenticate with key and passphrase $ssh2->auth_publickey($remote_login, $pub_key_file, $priv_key_file +, $remote_password) or die "\nERROR03 Unable to login $@ \n"; ($code, $error_name, $error_string) = $ssh2->error(); if ($code ne 0) { &log("error011","code = $code"); &log("error012","error_name = $error_name"); &log("error013","error_string = $error_string"); } } else { # authenticate with user and password $ssh2->auth_password($remote_login,$remote_password) or die "\nERR +OR04 Unable to login $@ \n"; ($code, $error_name, $error_string) = $ssh2->error(); if ($code ne 0) { &log("error021","code = $code"); &log("error022","error_name = $error_name"); &log("error023","error_string = $error_string"); } } # DE-Block SSH2 for channel open (blocking to 1) $ssh2->blocking(1); # open channel 1 $chan1 = $ssh2->channel(); ($code, $error_name, $error_string) = $ssh2->error(); if ($code ne 0) { &log("error031","code = $code"); &log("error032","error_name = $error_name"); &log("error033","error_string = $error_string"); } # Block SSH2 for channel shell (blocking to 0) $ssh2->blocking(0); ($code, $error_name, $error_string) = $ssh2->error(); if ($code ne 0) { &log("error051","code = $code"); &log("error052","error_name = $error_name"); &log("error053","error_string = $error_string"); } # start channel shell $chan1->shell(); # send a CR to initialize the session print $chan1 "\n";
    Regards Charles.

      I'd just like to chime in here that I was experiencing the same problem as madhurikl. I unexplainedly could not establish a connection on my SLES11 SP1 remote hosts. The above code snippet is useful for debugging exactly what the problem is. In my case, SLES was rejecting the authentication.

      error021code = -18 error022error_name = LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED error023error_string = Authentication failed (username/password)

      For whatever reason, the Net::SSH2 methods auth and auth_password just don't work on SLES11. However, auth_keyboard works perfectly fine. Problem solved. However, I suspect this should really just be a lesson to both of us to start using keys for authentication in the future.

      -Matt
Re^3: Net::SSH2::Channel with exec, reads 0 bytes on suse while works fine on ubuntu
by salva (Canon) on May 02, 2011 at 14:56 UTC