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

Hi Monks,

a strange device and I having a litte fight here and currently I'm loosing - that's why I ask for help... :-)

I'd like to connect and get noticed that it did not work. From cmd line: the device does not respond for 60sec, asks for user and pwd after that. (user and pwd will not work in that case - I know and that's fine, only trying to get an error for unsucessfull login....)

$ssh = Net::OpenSSH->new( $device, user => $sshuser, passwd => $sshpwd, ctl_dir => "/tmp/ssh.$$", master_opts => [-o => "StrictHostKeyChecking=no"], timeout => 90, kill_ssh_on_timeout => 1, strict_mode => 0, master_stderr_discard => 0 # to suppres login screen ); print ( "did ssh (".$ssh->error.")\n");
after 60 seconds I get the print and ssh->error = 0!

I'd expect an error.... Did I get something wrong?

Any hints are welcome

Replies are listed 'Best First'.
Re: Net::OpenSSH help needed
by salva (Canon) on Jul 30, 2013 at 10:57 UTC
    Activate debugging on the module and post here the output:
    $Net::OpenSSH::debug = -1;
      # ctl_path: /tmp/Ssh.18151/willnotwork-user-MUC-18151-77876, ctl_dir: +/tmp/Ssh.18151/ # set_error(0 - 0) # call args: ['ssh','-o','StrictHostKeyChecking=no','-o','ServerAliveI +nterval=30','-x2MN','-o','NumberOfPasswordPrompts=1','-o','PreferredA +uthentications=keyboard-interactive,password','-S','/tmp/Ssh.18151/wi +llnotwork-user-MUC-18151-77876','-l','willnotwork-user','MYDEVICE','- +-'] doing ssh # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # tracer attached, ssh pid: 18166, tracer pid: 18167 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 [remove tons of lines] # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 Welcome # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # passwd/passphrase requested (willnotwork-user@MYDEVICE's password:) # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object not yet found at /tmp/Ssh.18151/willnotwork-user-MUC-181 +51-77876 # file object found at /tmp/Ssh.18151/willnotwork-user-MUC-18151-77876 # call args: ['ssh','-O','check','-T','-S','/tmp/Ssh.18151/willnotwork +-user-MUC-18151-77876','-l','willnotwork-user','MYDEVICE','--'] # open_ex: ['ssh','-O','check','-T','-S','/tmp/Ssh.18151/willnotwork-u +ser-MUC-18151-77876','-l','willnotwork-user','MYDEVICE','--'] # io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 28 at offset 0 #> 4d 61 73 74 65 72 20 72 75 6e 6e 69 6e 67 20 28 70 69 64 3d 31 38 3 +1 36 36 29 0d 0a | Master running (pid=18166).. # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 0 at offset 28 # leaving _io3() # waiting for slave, timeout: 90, remaining: 90, sleep: 1 # _waitpid(20526) => pid: 20526, rc: Interrupted system call # DESTROY(Net::OpenSSH=HASH(0x96fe218), pid: 18166) # killing master # sending exit control to master # call args: ['ssh','-O','exit','-T','-S','/tmp/Ssh.18151/willnotwork- +user-MUC-18151-77876','-l','willnotwork-user','MYDEVICE','--'] # open_ex: ['ssh','-O','exit','-T','-S','/tmp/Ssh.18151/willnotwork-us +er-MUC-18151-77876','-l','willnotwork-user','MYDEVICE','--'] did ssh (0) # io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 20 at offset 0 #> 45 78 69 74 20 72 65 71 75 65 73 74 20 73 65 6e 74 2e 0d 0a + | Exit request sent... # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 0 at offset 20 # leaving _io3() # _waitpid(20527) => pid: 20527, rc: # _kill_master: 18166 # waitpid(master: 18166) => pid: 0, rc: # waitpid(master: 18166) => pid: 18166, rc: Interrupted system call



      from cmd line:
      ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -x2MN -o NumberOfPasswordPrompts=1 -o PreferredAuthentications=keyboard-interactive,password -l willnotwork-user MYDEVICE

      Welcome willnotwork-user@MYDEVICE's password: Connection closed by 123.123.123.123
        Strange, the connection seems to be established correctly even when the authentication fails.

        Enable debugging also for the ssh binary:

        $Net::OpenSSH::debug = -1; $ssh = Net::OpenSSH->new( $device, user => $sshuser, passwd => $sshpwd, ctl_dir => "/tmp/ssh.$$", master_opts => [-o => "StrictHostKeyChecking=no", '-vvv'], timeout => 90, kill_ssh_on_timeout => 1, strict_mode => 0 ); print STDERR "ssh error: " . $ssh->error . "\n";
Re: Net::OpenSSH help needed
by Loops (Curate) on Jul 30, 2013 at 10:45 UTC

    It sounds like you're actually getting logged in successfully. Try adding these lines to the bottom of your script (assuming the remote device logs you into a *nix shell):

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

    You should see the remote directory listing if you are successfully connecting.

      yep - and that's my problem....
      user/pwd definetly dont't work...