bighnaraj has asked for the wisdom of the Perl Monks concerning the following question:

Hello Salva and others ... Can you please help me as I am getting error while trying to ssh to a HP-UX box from Linux Machine.I am getting below error ....
[bmallik@null-001485a93da4 ~]$ perl -w RDF.pl ********************************************************************** +***** Qwest computers and the Qwest computer network are Qwest property. Only authorized persons may use them and only for legal and proper pur +poses as determined solely by Qwest. Users consent to the monitoring of the +ir use. Employees must use Qwest computers and the network in accordance with +the Qwest Code of Conduct, subject to discipline for misuse. Customer use +is governed by the Qwest Acceptable Use Policy. ---------------------------------------------------------------------- +---- NOTE: This server is NOT under IBM full support. Instead it is under a Maintenance Plus contract and support is through a Qwest support group +. For UNIX system adminstration support and work requests for this syste +m, please refer to the instructions found on this URL: http://sm-unix.uswc.uswest.com or contact the Help Desk at 1-877-828-4357 (see TheQ web page). ********************************************************************** +***** Couldn't establish SSH connection: unable to establish master SSH conn +ection: control command failed: child exited with code 1 at RDF.pl li +ne 14. [bmallik@null-001485a93da4 ~]$
SO This error comes just after it try to be connected ....I dont know wehre it gets stucked.I am not a perl expert.I am giving the code also as below ...
#!/usr/bin/perl use Net::OpenSSH; #use Math::Pari; my $host="hplwp638"; my $user="radarop"; my $password="XXXXX"; #$InHandle = $ssh->input_log("RDFinlog.txt"); #$OutHandle = $ssh->output_log("RDFoutlog.txt"); my $ssh= Net::OpenSSH->new($host,user=>$user, passwd=>$password); $ssh->error and warn "Couldn't establish SSH connection: ". $ssh->erro +r; #print "Trying to connect to $host now\n"; #$ssh->waitfor(String => 'hplwp638#[/home/radarop]'); #print $ssh->cmd("who"); my @output = $ssh->capture("who"); print @output;
Now I am getting below erroe after changing my code in a single line ....
my $ssh= Net::OpenSSH->new($host,user=>$user, passwd=>$password, stric +t_mode => 0, ctl_dir => "/tmp/~.libnet-openssh-perl" );
Error
[bmallik@null-001485a93da4 ~]$ perl -w RDF.pl Couldn't establish SSH connection: unable to establish master SSH conn +ection: the authenticity of the target host can't be established, the + remote host public key is probably not present on the '~/.ssh/known_ +hosts' file at RDF.pl line 14.

Replies are listed 'Best First'.
Re: Error in Login by useing Net::OpenSSH
by Plankton (Vicar) on Nov 10, 2011 at 05:59 UTC
    There probably isn't anything wrong with your Perl code. Can you ssh via the command line? There are a lot reason why a ssh connection could fail. OpenSSH has excellent documentation here: http://www.openssh.org/manual.html. You might want to try executing ssh from the command line and add verbosity with the -vvvv switch.
Re: Error in Login by useing Net::OpenSSH
by salva (Canon) on Nov 10, 2011 at 07:25 UTC
    The module documentation contains a troubleshooting chapter. Follow it, specially point 3.

    If after that, it still fails to connect, try this:

    Enable the module debugging: $Net::OpenSSH::debug = -1;

    Enable verbosity on the ssh command adding the following option on the constructor call:

    my $ssh= Net::OpenSSH->new(..., master_opts => '-vvv');

    and then, post here the output you get.

Re: Error in Login by useing Net::OpenSSH
by Plankton (Vicar) on Nov 11, 2011 at 06:34 UTC
    Hmmm ...
    Couldn't establish SSH connection: unable to establish master SSH conn +ection: the authenticity of the target host can't be established, the + remote host public key is probably not present on the '~/.ssh/known_ +hosts' file at RDF.pl line 14.
    ... actually this error message tells us a lot. It tells us that the remote host public key is not in ~/.ssh/known_hosts file. After looking and man ssh_config one can see that this can be controlled by the ssh client with the StrictHostKeyChecking option. From the ssh_config man page:

    If this flag is set to “yes”, ssh(1) will never automatically add host keys to the ~/.ssh/known_hosts file, and refuses to connect to hosts whose host key has changed. This provides maximum pro‐ tection against trojan horse attacks, though it can be annoying when the /etc/ssh/ssh_known_hosts file is poorly maintained or when connections to new hosts are frequently made. This option forces the user to manually add all new hosts. If this flag is set to “no”, ssh will automatically add new host keys to the user known hosts files. If this flag is set to “ask”, new host keys will be added to the user known host files only after the user has confirmed that is what they really want to do, and ssh will refuse to connect to hosts whose host key has changed. The host keys of known hosts will be verified automatically in all cases. The argument must be “yes”, “no”, or “ask”. The default is “ask”.

    So you may want to disable StrictHostKeyChecking by doing something like:

    $ssh = Net::OpenSSH->new($host, master_opts => [-o => "StrictHostKeyChecking=no"], ...);
      Was having the same problem and this helped! Thanks! :)

        Thanks a lot, your solution saved my day !!