can't ssh:unable to establish master SSH connection: bad password or master process exited unexpectedly

南笙酒味 提交于 2021-01-28 04:13:18

问题


I have problem with perl modules, i 'm trying to connect to the remote server using the OpenSSH module from CPAN and i have given the username and password correctly but when i run my CGI from browser i see the following error message "

can't ssh:unable to establish master SSH connection: bad password or master process exited unexpectedly

in need of immediate reply's and awaiting, Thanks in Advance.

Here is my code

#!/usr/bin/perl -w
use CGI;
use Data::Dumper;
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Net::OpenSSH;


my $query = CGI->new();
#my $mach_name=$query->param('mach_name');
my $mach_name= '****.cce.***.com';
my $user='root';
my $passwd='*******';
my $ssh = Net::OpenSSH->new("$mach_name",user => "$user" , passwd => "$passwd
", master_opts => [-o => "strictHostKeyChecking=no"]);
$ssh->error and die "can't ssh:" . $ssh->error;
my $mem_info =$ssh->capture("ioscan -m lun");
print "$mem_info";
print "Content-type: text/html\n\n";
print "<html><head><title>test page</title></head>\n";
print "<body><p>Dicovering Machine Please wait....</p>\n";
print "<p>$mach_name</p>";
print "<p><b>Swap Memory :$mem_info </b> </p>";
print "</body></html>";

The same program if i run through the command line it is getting the o/p but through the browser i'm seeing the above error i have given the passwd and username correctly


回答1:


My problem was solved when I've increased the timeout from 10 seconds to 15 seconds, because the device is using an older SSH daemon version, but my linux server that made the client connection is upgraded and of course it probes first the newer ciphers.

my $ssh = Net::OpenSSH->new(
$host,
port                => $port,
user                => $user,
password            => $pass,
timeout             => 15,       # <= this was 10 and now is 15
kill_ssh_on_timeout => 1,
strict_mode         => 0,
master_opts         => [-o => "StrictHostKeyChecking=no", '-vvv'], #<= -vvv helped much
ctl_dir             =>'/tmp/libnet-openssh-perl',



回答2:


Looks like some permissions issue. Run ssh in verbose mode:

my $ssh = Net::OpenSSH->new("$mach_name",
                             user => "$user", 
                             passwd => "$passwd",
                             master_opts => '-vvv',
                             master_stderr_fh => \*LOG);

If that doesn't give you enough information about the cause of the problem, then, you can use truss to see what's happening at the OS level.

Also check .ssh/known_hosts, make sure .ssh directory is writeable by Apache. .libnet-openssh-perl directory should be writeable by Apache.

For example, my Apache user is apache with a home directory of /var/www I have /var/www/.ssh owned by apache, and /var/www/.libnet-openssh-perl owned by apache. I ssh to devices using my own account, then copy my known_hosts file to /var/www/.ssh/known_hosts



来源:https://stackoverflow.com/questions/23605605/cant-sshunable-to-establish-master-ssh-connection-bad-password-or-master-proc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!