Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Net::OpenSSH::Compat::SSH2 auth_password fails

by madhurikl (Novice)
on May 12, 2015 at 11:11 UTC ( [id://1126408]=note: print w/replies, xml ) Need Help??


in reply to Re: Net::OpenSSH::Compat::SSH2 auth_password fails
in thread Net::OpenSSH::Compat::SSH2 auth_password fails

Here is the code and the output :

Code :

use Net::OpenSSH::Compat::SSH2 qw(:supplant); use Net::SSH2; $Net::OpenSSH::debug=-1; my $ip = 'xxx'; my $port = 22; my $username = 'user1'; my $password = 'user1'; my $ssh2 = Net::SSH2->new(); $ssh2->connect($ip,$port) or die $!; my $res = $ssh2->auth(username => $username, password => $password,) or die "$!",$ssh2->error +; print "result is $res\n";

Output :

> perl compatssh2.pl # ctl_path: /home/smokes/.libnet-openssh-perl/regression-192.168.2.-11 +175-417065, ctl_dir: /home/smokes/.libnet-openssh-perl/ # _is_secure_path(dir: /home/smokes/.libnet-openssh-perl, file mode: 1 +6832, file uid: 1003, euid: 1003 # _is_secure_path(dir: /home/smokes, file mode: 16877, file uid: 1003, + euid: 1003 # set_error(0 - 0) # call args: ['ssh','-o','ServerAliveInterval=30','-x2MN','-o','Number +OfPasswordPrompts=1','-o','PreferredAuthentications=keyboard-interact +ive,password','-S','/home/smokes/.libnet-openssh-perl/user1-192.168.2 +.-11175-417065','-l','user1','-p',22,'192.168.2.215','--'] # file object not yet found at /home/smokes/.libnet-openssh-perl/regre +ssion-192.168.2.-11175-417065 # file object not yet found at /home/smokes/.libnet-openssh-perl/regre +ssion-192.168.2.-11175-417065 # file object not yet found at /home/smokes/.libnet-openssh-perl/regre +ssion-192.168.2.-11175-417065 # file object not yet found at /home/smokes/.libnet-openssh-perl/regre +ssion-192.168.2.-11175-417065 # file object not yet found at /home/smokes/.libnet-openssh-perl/regre +ssion-192.168.2.-11175-417065 # file object not yet found at /home/smokes/.libnet-openssh-perl/regre +ssion-192.168.2.-11175-417065 # tracer attached, ssh pid: 11177, tracer pid: 11178 # set_error(1 - unable to establish master SSH connection: the authent +icity of the target host can't be established, the remote host public + key is probably not present on the '~/.ssh/known_hosts' file) # _kill_master: 11177 # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 0, rc: # killing master with signal TERM # waitpid(master: 11177) => pid: 0, rc: # waitpid(master: 11177) => pid: 11177, rc: Interrupted system call # DESTROY(Net::OpenSSH=HASH(0xdb75b0), pid: <undef>) Interrupted system callLIBSSH2_ERROR_SOCKET_DISCONNECTunable to establ +ish master SSH connection: 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 compatssh2.pl line 13.

Replies are listed 'Best First'.
Re^3: Net::OpenSSH::Compat::SSH2 auth_password fails
by salva (Canon) on May 12, 2015 at 11:31 UTC
    The problem is...
    unable to establish master SSH connection: the authenticity of the tar +get host can't be established, the remote host public key is probably + not present on the '~/.ssh/known_hosts' file

    The thing is that Net::SSH2 is insecure by default. It doesn't check the public key of the remote host unless the programmer explicitly does it and AFAIK, nobody actually does it.

    On the other hand Net::OpenSSH always checks the remote host key. I could change Net::OpenSSH::Compat::SSH2 to behave in the same way, but well, that wouldn't let me sleep at night... promoting such sloppy programming practice!!!

    Anyway, as a work around just log into the remote machine from the command line using ssh so that the remote host key is stored in ~/.ssh/known_hosts and from that moment your code should work.

      Thanks salva, that worked.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1126408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found