Perl:使用 Net::OpenSSH 的 scp_put 拒绝权限

Posted

技术标签:

【中文标题】Perl:使用 Net::OpenSSH 的 scp_put 拒绝权限【英文标题】:Perl: Permission Denied with scp_put of Net::OpenSSH 【发布时间】:2016-08-21 16:48:09 【问题描述】:

我正在尝试使用Net::OpenSSHscp_put 函数将文件SCP 到远程机器中。每次运行时,我都会收到以下错误:

scp failed: scp failed: child exited with code 1 at copy_certs.pl line 32.

这是我尝试此操作的代码 sn-p:

use Net::SSH::Perl;
use Exporter;
use Net::OpenSSH;

my $user = "hello";
my $pass = "hello";
my $remote_path = "/hello_folder/ssl";

$host="10.221.33.4";
my $ssh = Net::OpenSSH->new($host, user => $user, password => $pass, master_opts => [-o => "StrictHostKeyChecking=no"]);    
$key_file = "certs/mykey.key";
$ssh->scp_put($key_file, $remote_path)
                or die "scp failed: " . $ssh->error;

当我手动执行此操作时,我没有任何权限问题。我哪里错了?

【问题讨论】:

启用调试$Net::OpenSSH::debug=-1 并在此处附加输出。它将向我们展示模块在后台运行的命令。 【参考方案1】:

如果远程主机密钥已更改,则会出现权限问题。通过运行以下命令删除远程机器的 RSA 密钥 - "ssh-keygen -f "/.ssh/known_hosts" -R " 再试一次。

【讨论】:

试过了,不是问题。

以上是关于Perl:使用 Net::OpenSSH 的 scp_put 拒绝权限的主要内容,如果未能解决你的问题,请参考以下文章