ssh:无法建立主ssh连接:密码错误或主进程意外退出

时间:2022-10-28 00:16:09

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 "

我有perl模块的问题,我试图使用CPAN中的OpenSSH模块连接到远程服务器,我已经正确地给出了用户名和密码,但是当我从浏览器运行CGI时,我看到了以下错误消息

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

ssh:无法建立主ssh连接:密码错误或主进程意外退出

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

同样的程序如果我在命令行中运行它会得到o/p但是通过浏览器我看到上面的错误,我已经正确地给出了passwd和username

2 个解决方案

#1


2  

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.

当我将超时时间从10秒增加到15秒时,我的问题就解决了,因为设备使用的是较老的SSH守护进程版本,但是我的linux服务器升级了客户端连接,当然它首先探测更新的密码。

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


0  

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

看起来有一些权限问题。在详细模式下运行ssh:

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.

如果这不能提供足够的关于问题原因的信息,那么您可以使用truss查看操作系统级别上发生的事情。

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

还要检查.ssh/known_hosts,确保.ssh目录可以由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

例如,我的Apache用户是Apache,其主目录为/var/www。apache拥有的ssh和/var/www/。libnet-openssh-perl由apache。我使用自己的帐户ssh到设备,然后将我的known_hosts文件复制到/var/www/.ssh/known_hosts

#1


2  

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.

当我将超时时间从10秒增加到15秒时,我的问题就解决了,因为设备使用的是较老的SSH守护进程版本,但是我的linux服务器升级了客户端连接,当然它首先探测更新的密码。

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


0  

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

看起来有一些权限问题。在详细模式下运行ssh:

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.

如果这不能提供足够的关于问题原因的信息,那么您可以使用truss查看操作系统级别上发生的事情。

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

还要检查.ssh/known_hosts,确保.ssh目录可以由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

例如,我的Apache用户是Apache,其主目录为/var/www。apache拥有的ssh和/var/www/。libnet-openssh-perl由apache。我使用自己的帐户ssh到设备,然后将我的known_hosts文件复制到/var/www/.ssh/known_hosts