目次

Net::OpenSSH

Perl で ssh 接続

StrictHostKeyChecking=no は既知1)でないhostに接続する場合のエラーを抑制します。

# コネクト
$ssh = Net::OpenSSH->new(
    'hostname'
    ,(user => 'username',password => 'Passw0rd')
    , master_opts => [-o => "StrictHostKeyChecking=no"]
);
 
# 結果表示
say $ssh->capture('cat /etc/redhat-release');
 
# コマンド結果をキャプチャ
my @ls = $ssh->capture("ls");
$ssh->error and die "remote ls command failed: " . $ssh->error;

参考

ドキュメント

1)
KnownHost