Perl Net::OpenSSH 连接到需要 RSA 和密码的服务器

问题描述 投票:0回答:1

我必须连接到使用 RSA 密钥和密码进行身份验证的服务器。但是,我在让它在 Net::OpenSSH 中实际工作时遇到问题。

如果我尝试从命令行读取 myuser 的 RSA,然后提示输入密码(不是 RSA 密码,因为测试时为空): 'sudo -u myuser ssh myuser@hostip 这很好用。 但是,在 perl 中,它无法连接,并声称 RSA 密钥失败。 “权限被拒绝(公钥)。”

my $ssh = Net::OpenSSH->new($server, user => $username, password => $passwd, timeout => 10,master_opts => [-o => "UserKnownHostsFile=/dev/null"]);
$ssh->error and die "Unable to connect: " . $ssh->error;

我将 perl 脚本作为从命令行成功工作的同一用户进行 sudoing,因此它应该使用其 RSA 密钥,但不知何故,它的行为就好像根本没有发送一样。

知道我错过了什么吗?

perl openssh
1个回答
0
投票

要将 Net::OpenSSH 与 RSA 密钥一起使用,您应该使用

key_path
passphrase
选项。

my $ssh = Net::OpenSSH->new($host,
                            key_path => $keyfile,
                            passphrase => $password);
$ssh->error and
    die "Couldn't establish SSH connection: ". $ssh->error;
$ssh->system("ls /tmp") or
    die "remote command failed: " . $ssh->error;
© www.soinside.com 2019 - 2024. All rights reserved.