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

Trying to keep it simple, I am unable to connect to a remote test platform using openssh with ActivePerl under windows, I am able to secure shell into the server in question using a CRT application.

My code is below:

#!/usr/bin/perl use Net::OpenSSH; $Net::OpenSSH::debug = ~0; my $ssh = Net::OpenSSH->new("root:viking@10.0.0.29",timeout => 30,stri +ct_mode => 0); $ssh->error and die "Unable to connect: " + $ssh->error; print "Connected to $ssh\n"; undef $ssh;

the output I receive is:

c:\Users\lax1_test\Desktop\ASRT_trunk>perl -w test.pl # open_ext: ['ssh','-V'] # io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0

Replies are listed 'Best First'.
Re: basic openssh connectivity
by salva (Canon) on Jul 26, 2019 at 08:26 UTC

      Thanks, I was suspecting that would be the ultimate answer. Only Net::SSH::Any appears to be built for Windows, I was able to get a handle back from the constructor, but when I ran capture I got the message:

      "PTYs are not supported on Windows"

      Researching that message sent me down another rat hole. Is there anyone who uses SSH with ActiveState perl under windows 64 to log into remote Linux servers with a script? If so could you tell me which package you use and how you installed it? If no one is successfully using SSH with ActiveState. How about Strawberry?

      Brian

        Both Net::SSH2 and Net::SSH::Perl can be installed on Windows, though doing it is not easy, specially with ActiveState Perl.

        Net::SSH2 is included with Strawberry Perl.

        Net::SSH::Any does not handle the SSH connection by itself but delegates it to some module implementing the SSH protocol (currently Net::SSH2 or Net::OpenSSH) or to some external command as plink or ssh. Every backend has its limitations. For instance, only a few ones support password authentication.

Re: basic openssh connectivity
by 1nickt (Canon) on Jul 26, 2019 at 01:02 UTC

    Hi, here are a couple of observations (not on Windows).

    • You are not using strict or warnings, so you prevented Perl from telling you about any errors or warnings it finds.

    • You are trying to append the error string with + which is the numeric addition operator. You need the string concatenation operator .

    • You are using double quotes around your hostname, so Perl is trying to expand a (non-existent?*) array `@10` and the resulting host is invalid: I got "Bad port 'viking.0.0.29'". You need single quotes.

    • After fixing those things I got "# file object not yet found at /Users/1nickt/.libnet-openssh-perl/6c2386dc6c577f876ea5abdc069663a6, state:_STATE_LOGIN" from the debug ad infinitum, as expected. (BTW I know that's a private net, but one hopes those are not real credentials in your OP.)

    Hope this helps!

    (*) I don't understand where this array is found and don't have time to deparse the code right now.


    The way forward always starts with a minimal test.
      > I don't understand where this array is found

      It's a global array, because we have $1, $2, $3, and $10 as well; and it exist as a *10 glob with all the possible slots, array being one of them.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Thanks choroba I figured it was a global, but didn't think that it would have been defined since no regexp match was attempted. I would have expected to get an error when Perl tried to interpolate it as it was not defined.


        The way forward always starts with a minimal test.

      Hi, thanks so much for the reply. A little background: I am using ActivePerl 5.26.3 build 2603 64 bit. I made a couple of changes based on your comments see below:

      #!/usr/bin/perl use Net::OpenSSH; $Net::OpenSSH::debug = ~0; print "open secure shell\n"; my $ssh = Net::OpenSSH->new('10.0.0.29',timeout => 30, user => 'root', + password => 'viking',port => 22); print "returned from secure shell\n"; $ssh->error and print "Unable to connect: " . $ssh->error; print "Connected to $ssh\n"; undef $ssh;

      Output

      open secure shell # open_ex: ['ssh','-V'] # io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0

      I guess what bothers me is that control never seems to return from the constructor. It goes in, but doesn't come out.

        I should clarify that it doesn't hang in the constructor, the script just ends without returning from the constructor.