Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Below is about the minimum Perl code that worked for me on Debian machine. I suggest you go through it and compare it to your actual code.</p> <p>However, it did not work out-of-the box on my Debian, I had make some decisions most of which probably aren't very safe, but that's more about specific environment:</p> <ul> <li>make home for user that server runs writable (/var/www)</li> <li>add host to ~/.ssh/known_hosts beforehand</li> <li>use the <code>strict_mode =&gt; 0</code> to bypass <code>Net::OpenSSH</code>'s security checks instead of finding proper <code>ctl_dir</code> (<code>Net::OpenSSH</code> requires that the folder <em>and all above folders</em> are 0755 or more strict, so /tmp I used is normally not good enough)</li> </ul> <p>I believe there are much safer practices than that, but as I said, that's specific to environment.</p> <p>So the code:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use File::Temp qw/ tempdir /; # necessary minimum for CGI print "Content-type: text/plain\n\n"; # prepare temp dir my $temp = tempdir("/tmp/sshme.pl-XXXXXXXX", CLEANUP =&gt; 1); # open SSH session my %opts = ( user =&gt; "user", password =&gt; "password", ctl_dir =&gt; $temp, strict_mode =&gt; 0 ## NOT recommended - see my comments ); my $ssh = Net::OpenSSH-&gt;new("host", %opts); $ssh-&gt;error and die "Couldn't establish SSH connection: ". $ssh-&gt;error; # perform command and print output my @lines = $ssh-&gt;capture("ls") or die "remote command failed: " . $ssh-&gt;error; print @lines; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload