CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Reg: Net::OpenSSH module

 



gopisera
Novice

Apr 3, 2010, 7:19 AM

Post #1 of 11 (8746 views)
Reg: Net::OpenSSH module Can't Post

Hi,



I have installed Net::OpenSSH module successfully.

When i am using the object and calling the constructor i am getting the following error

SSH connection failed: unable to establish master SSH connection: ssh master exited unexpectedly at connect.pl line 19.


The program Source Code is

#!/usr/local/bin/perl -wTU
use vars;

use lib "/export/home/oracle/scripts/gopisera/IO-Tty/lib/site_perl/5.8.4/sun4-solaris-64int";
use lib "/export/home/oracle/scripts/gopisera/lib/perl5/site_perl/5.8.0";
use lib "/usr/local/lib/perl5/5.8.0";
#use lib "/u01/app/oracle/product/10.2.0/Apache/Apache/cgi-bin/gopisera/username/Net-SSH-Expect-1.09/lib/Net/SSH";
#use lib "/export/home/oracle/scripts/gopisera/lib/perl5/site_perl";
#use lib "/export/home/oracle/scripts/gopisera/IOT/lib/site_perl/5.8.4/sun4-solaris-64int";

use strict;
use Net::OpenSSH;
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
$ENV{'PATH'}='';
my $ssh = Net::OpenSSH->new('oracle@10.14.2.150', password => 'xxxxx', ssh_cmd => '/usr/local/bin/ssh', master_stderr_discard => 1);
$ssh->error and die "SSH connection failed: " . $ssh->error;

my $command = "ls";
my @out = $ssh->capture($command);
print "@out";







I have tried variously, such as below

#my $ssh = Net::OpenSSH->new('gopisera@[172.30.231.231]', passwd => 'xxxxxx', master_stderr_discard => 1);
#my $ssh = Net::OpenSSH->new('172.30.231.231', user => 'gopisera', port => '22', passwd => 'xxxxxx', master_stderr_discard => 1);

#my $ssh = Net::OpenSSH->new('oracle@172.30.231.243:22');

But still i am facing the same problem...............



Can any one rectify the above ......



let me know I have few more doubts regarding this What are the neccessary i mean compulsary parameters to send through this constructor....

The modules are installed correctly and while installing all it shows success i mean the make test is successfull.



Please respond for this .........

It's very urgent>>>>>>>

Waiting for the reply,,,,



Thanks,

Ramesh G


FishMonger
Veteran / Moderator

Apr 3, 2010, 8:03 AM

Post #2 of 11 (8742 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post

It would appear to me that the error message is telling you that it's having an authentication problem.

I have not used that module, but the first step would be to enable debug. Add this before creating the object.

Code
$Net::OpenSSH::debug |= 16;


Some side comments on your code.
1) It's preferable to use the warnings pragma instead of the -w switch.

2) Why use both -T and -U switches? They basically cancel out each other.

3) Why are you using the obsolete vars pragma and why aren't you passing it any vars?

4) This is purely a matter of personal style, but I prefer to load the warnings and strict pragmas at the beginning and the rest of the use statements immediately after them.


FishMonger
Veteran / Moderator

Apr 3, 2010, 8:14 AM

Post #3 of 11 (8742 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post

See if this slightly cleaned up version of your code helps.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use Net::OpenSSH;
use lib "/export/home/oracle/scripts/gopisera/IO-Tty/lib/site_perl/5.8.4/sun4-solaris-64int";
use lib "/export/home/oracle/scripts/gopisera/lib/perl5/site_perl/5.8.0";
use lib "/usr/local/lib/perl5/5.8.0";

delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
$ENV{'PATH'}='';

$Net::OpenSSH::debug |= 16;

my $ssh = Net::OpenSSH->new('10.14.2.150',
user => 'oracle',
password => 'xxxxx',
ssh_cmd => '/usr/local/bin/ssh',
);

$ssh->error and die "SSH connection failed: " . $ssh->error;

my $command = "ls";
my @out = $ssh->capture($command);
print @out;



gopisera
Novice

Apr 3, 2010, 2:16 PM

Post #4 of 11 (8736 views)
Re: [FishMonger] Reg: Net::OpenSSH module [In reply to] Can't Post

Thanks for Quick reply

But when i run after modified program i have got the below error

ssh: illegal option -- M
Usage: ssh [options] host [command]
Options:
-l user Log in using this user name.
-n Redirect input from /dev/null.
-F config Config file (default: ~/.ssh/config).
-A Enable authentication agent forwarding.
-a Disable authentication agent forwarding (default).
-X Enable X11 connection forwarding.
-x Disable X11 connection forwarding (default).
-i file Identity for public key authentication (default: ~/.ssh/identity)
-t Tty; allocate a tty even if command is given.
-T Do not allocate a tty.
-v Verbose; display verbose debugging messages.
Multiple -v increases verbosity.
-V Display version number only.
-P Don't allocate a privileged port.
-q Quiet; don't display any warning messages.
-f Fork into background after authentication.
-e char Set escape character; ``none'' = disable (default: ~).
-c cipher Select encryption algorithm
-m macs Specify MAC algorithms for protocol version 2.
-p port Connect to this port. Server must be on the same port.
-L listen-port:host:port Forward local port to remote address
-R listen-port:host:port Forward remote port to local address
These cause ssh to listen for connections on a port, and
forward them to the other side by connecting to host:port.
-D port Enable dynamic application-level port forwarding.
-C Enable compression.
-N Do not execute a shell or command.
-g Allow remote hosts to connect to forwarded ports.
-1 Force protocol version 1.
-2 Force protocol version 2.
-4 Use IPv4 only.
-6 Use IPv6 only.
-o 'option' Process the option as if it was read from a configuration file.
-s Invoke command (mandatory) as SSH2 subsystem.
-b addr Local IP address.
SSH connection failed: unable to establish master SSH connection: ssh master exited unexpectedly at connect.pl line 21




I couldn't understand why the authenticattion is needed for the above since, as we are supplying i.e., mentioning the password for that user also.

And one more thing is that for using the -T and -U in my program since, Tainting and un Tainting of objects because if i am not using those options i am getting the below error

Use of reserved word "our" is deprecated at /export/home/oracle/scripts/gopisera/lib/perl5/site_perl/5.8.0/Net/OpenSSH.pm line 3.
Can't modify subroutine entry in scalar assignment at /export/home/oracle/scripts/gopisera/lib/perl5/site_perl/5.8.0/Net/OpenSSH.pm line 3, near "'0.45';"
BEGIN not safe after errors--compilation aborted at /export/home/oracle/scripts/gopisera/lib/perl5/site_perl/5.8.0/Net/OpenSSH.pm line 5.


BEGIN failed--compilation aborted at connect.pl line 12





Please give me again a suggestion for this.......

Waiting for your reply....

As there is any link with the ssh-keygen-g3 authentication key pair generator for getting the error....????





Thanks,

Ramesh G


FishMonger
Veteran / Moderator

Apr 3, 2010, 2:55 PM

Post #5 of 11 (8728 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post

What is the module version?

Please post the first 20 or so lines of the module.


gopisera
Novice

Apr 3, 2010, 3:03 PM

Post #6 of 11 (8725 views)
Re: [FishMonger] Reg: Net::OpenSSH module [In reply to] Can't Post

Version is 0.45


gopisera
Novice

Apr 3, 2010, 3:05 PM

Post #7 of 11 (8724 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post

package Net::OpenSSH;

our $VERSION = '0.45';

use strict;
use warnings;

our $debug ||= 0;

use Carp qw(carp croak);
use POSIX qw(:sys_wait_h);
use File::Spec;
use Cwd ();
use Scalar::Util ();
use Errno ();
use Net::OpenSSH::Constants qw(:error);

sub _debug { print STDERR '# ', (map { defined($_) ? $_ : '<undef>' } @_), "\n" }

sub _debug_dump {
require Data::Dumper;
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Indent = 0;
my $head = shift;
_debug("$head: ", Data::Dumper::Dumper(@_));
}

sub _hexdump {
no warnings qw(uninitialized);
my $data = shift;
while ($data =~ /(.{1,32})/smg) {
my $line=$1;
my @c= (( map { sprintf "%02x",$_ } unpack('C*', $line)),
((" ") x 32))[0..31];
$line=~s/(.)/ my $c=$1; unpack("c",$c)>=32 ? $c : '.' /egms;
print STDERR "#> ", join(" ", @c, '|', $line), "\n";
}
}



Let me know your Gmail id (if you can) so, i can chat with you


gopisera
Novice

Apr 3, 2010, 3:06 PM

Post #8 of 11 (8723 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post

ramesh.g2005@gmail.com is my mail id


gopisera
Novice

Apr 3, 2010, 3:10 PM

Post #9 of 11 (8722 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post

After surfing in google i have seen that

for ssh [-1246AaCfgKkMNnqsTtVvXxYy] there will be an option M which is not there in my ssh version.

-M Places the ssh client into ``master'' mode for connection
sharing. Multiple -M options places ssh into ``master'' mode
with confirmation required before slave connections are accepted.
Refer to the description of ControlMaster in ssh_config(5) for
details.


If this is right can i install ssh of newer version in the user level. Since i doesn't have the root privielges. If so, Give me suggestion....

I am waiting for your reply.... :)


gopisera
Novice

Apr 4, 2010, 3:35 PM

Post #10 of 11 (8682 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post

Hi Friends,



I got the solution for that.

We should have OpenSSH should be installed which is shell executable.

It is complusory one which we can see in the readme file on Net::OpenSSH.

So, Downloaded the OpenSSH and while installing i have an error.

So, as general user trying to install the OpenSSH giving the error as not able to create a directory in /var/empty

used the commands

./configure prefix=<ourpath> sysconfig=<ourpathnew>

make

make install



So, then i left this and then i came to the module of Net::SSH::Perl::SSH2

For this i am getting the following error



DynaLoader object version 1.03 does not match $DynaLoader::VERSION 1.04 at /export/home/oracle/scripts/gopisera//Net_SSH/lib/perl5/site_perl/5.8.0/DynaLoader.pm line 78.


Can any one please give me the solution.



Thanks,

Ramesh G


salva
Novice

Apr 5, 2010, 7:11 AM

Post #11 of 11 (8650 views)
Re: [gopisera] Reg: Net::OpenSSH module [In reply to] Can't Post


In Reply To
So, Downloaded the OpenSSH and while installing i have an error.

So, as general user trying to install the OpenSSH giving the error as not able to create a directory in /var/empty


instead of building OpenSSH from source, get it and its dependencies as packages from SUN Freeware:


(This post was edited by salva on Apr 5, 2010, 7:12 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives