Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Using SSH and SCP in a perl script with taint flag

by salva (Canon)
on May 28, 2015 at 16:09 UTC ( [id://1128156]=note: print w/replies, xml ) Need Help??


in reply to Using SSH and SCP in a perl script with taint flag

Net::OpenSSH does support working on taint mode.
  • Comment on Re: Using SSH and SCP in a perl script with taint flag

Replies are listed 'Best First'.
Re^2: Using SSH and SCP in a perl script with taint flag
by stefl (Acolyte) on May 29, 2015 at 10:36 UTC

    Hi Salva, thanks for your reply. I've read through the documentation for OpenSSH and it seems like a much better method than my current attempts. I'm getting really confused though with the examples in the documentation, and my own attempts aren't going well. Would you be able to help further? My current code sample is below.

    #!/usr/bin/perl -wT use Net::OpenSSH; $ENV{PATH} = "/bin"; my $ssh = Net::OpenSSH->new("<IP>", user => "<username>", password => +"<password>"); $ssh->error and die "Can't ssh to host: " . $ssh->error; $ssh->system('whoami')or die "whoami failed: " .$ssh->error;

    I should say, I have tried this without the password bit (as I use private key authentication) as well, and I have tried using syntax such as  my $ssh = Net::OpenSSH->new("<user>\@<Host IP>");.
    I get the following error:

    Can't exec "ssh": No such file or directory at /usr/share/perl5/Net/Op +enSSH.pm line 731. Can't ssh to host: unable to establish master SSH connection: master p +rocess exited unexpectedly
    Do you have any further advice?
    Thanks very much again! Really appreciate your help.

      The problem is that the OpenSSH client ssh is not in the scrawny path you are using. Try adding /usr/bin too:
      $ENV{PATH} = "/bin:/usr/bin";

        Thanks very much salva, your advice was brilliant. Got it working now, you've saved me days of frustration! For anyone else in my situation who is new to this stuff, I fixed this by adding the ctl_dir option:  my $ssh = Net::OpenSSH->new($host, user=>$user, ctl_dir=>$ctldir);. I created the $ctldir (called .libnet-openssh-perl) within my /var/www directory and ensured the owner was www-data.
        I hope this can help someone else too! Thanks again salva, legend!

        Genius! Thanks very much! Is there anything special I need to do to get this to work when running the script as www-data? On the command line (to emulate running the webform) I run it as follows:  sudo -u www-data perl -T test but get an error message: Can't ssh to host: unable to create ctl_dir /var/www/.libnet-openssh-perl
        This might be more of a general Linux question, in which case I apologise. I am able to ssh as the www-data outwith the perl script though, so I don't know what is wrong.
        Thanks very much for your advice, you seem to know a lot about using this module and I'm very, very new to this sort of thing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-24 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found