Skip to content

Instantly share code, notes, and snippets.

@ddmitov
Created August 16, 2018 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddmitov/1527f9fca9fb954fed57d550571b4776 to your computer and use it in GitHub Desktop.
Save ddmitov/1527f9fca9fb954fed57d550571b4776 to your computer and use it in GitHub Desktop.
Execute remote commands using Perl5, Net::OpenSSH and a private key
#!/usr/bin/perl
use Net::OpenSSH;
my $ssh = Net::OpenSSH->new('root@server.domain.name', key_path => '/path/to/private_key');
$ssh->error and die "Couldn't establish SSH connection: ".$ssh->error;
my ($stdin, $stdout, $stderr, $pid) = $ssh->open3("ls -l");
my @output = <$stdout>;
print @output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment