Making Net::SCP work (CPAN, FTP_PASSIVE, sudo, visudo)

This is a short note regarding the motions I had to go through to make the perl module Net::SCP work. This is a note to self.

Step 0 - ¬†CPAN’s documentation is pretty straight-forward.
Step 1 - Installation

install Net::SCP

Oops.. Needs sudo permissions to perform make install

$sudo cpan

What!! Can not fetch LWP/FTP. Why? It just did it. FTP_PASSIVE is set as an environment variable (see my previous blog). Now what’s wrong.

Turns out sudo filters out most environment variables (FTP_PASSIVE not picked up). The fix is to edit /etc/sudoers

env_keep = ..... FTP_PASSIVE .....

So, I tried : sudo /etc/sudoers Read-only - Er.. For Root? Oh that’s a security feature, so let’s try : sudo visudo Err visudo doesn’t exist. It’s not in $PATH. All right sudo /usr/sbin/visudo.

Problem solved. Now sudo cpan can make install in peace and I can get around pesky firewall’s with passive FTP as root.

Oh and a code dump of what I was testing.

use strict;
use warnings;
use Net::SCP;

#used ssh-keygen -t rsa to generate key on local machine
#used ssh-copy-id -i ~/.ssh/ [remote_username]@[remote_machine] to share public key from [local_machine] to [remote_machine]

#otherwise replace Net::SCP->new("[remote_machine_name]“,”PASSWORD”);

my $scp;
$scp = Net::SCP->new(”[remote_machine]”);
$scp->put(”[what to put]”,”[where to put]”) or die $scp->{errstr};

This was pretty straight-forward.

Leave a Reply