为什么ssh在我把它交给Perl的Net :: SSH :: Perl之后会提示我输入密码?

Nin*_*nja 1 ssh perl

我使用Net :: SSH :: Perl在远程服务器上执行命令,如下所示:

use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);
Run Code Online (Sandbox Code Playgroud)

但是当我执行上面的脚本时,会再次出现密码提示.这意味着我在$ pass中提供的密码不用于建立ssh连接.为什么是这样?知道如何克服这个问题吗?我在下面给出调试信息:

serv1: Reading configuration data /root/.ssh/config
serv1: Reading configuration data /etc/ssh_config
serv1: Allocated local port 1023.
serv1: Connecting to 15.154.59.63, port 22.
serv1: Remote protocol version 1.99, remote software version OpenSSH_4.2
serv1: Net::SSH::Perl Version 1.34, protocol version 1.5.
serv1: No compat match: OpenSSH_4.2.
serv1: Connection established.
serv1: Waiting for server public key.
serv1: Received server public key (768 bits) and host key (1024 bits).
serv1: Host '15.154.59.63' is known and matches the host key.
serv1: Encryption type: DES3
serv1: Sent encrypted session key.
serv1: Received encryption confirmation.
serv1: RSA authentication failed: Can't load public key.
serv1: Doing challenge response authentication.
Password:

鉴于我已经在$ pass变量中提供了密码,密码提示不应该是正确的?

更新(根据收到的意见):

我尝试了以下方法:

my $ssh = Net::SSH::Perl->new($host, debug =>1, identity_files => []);
Run Code Online (Sandbox Code Playgroud)

现在,我没有收到消息"RSA身份验证失败:"但仍然出现密码提示.我在下面给出调试信息:

serv1: Allocated local port 1023. 
serv1: Connecting to 15.154.59.63, port 22. 
serv1: Remote protocol version 1.99, remote software version OpenSSH_4.2 
serv1: Net::SSH::Perl Version 1.34, protocol version 1.5. 
serv1: No compat match: OpenSSH_4.2. kf-linux-dm3: Connection established. 
serv1: Waiting for server public key. 
serv1: Received server public key (768 bits) and host key (1024 bits).
serv1: Host '15.154.59.63' is known and matches the host key.
serv1: Encryption type: DES3 
serv1: Sent encrypted session key.
serv1: Received encryption confirmation. 
serv1: Doing challenge response authentication. 
Password:

有人可以开导我吗?

Mar*_*off 5

你错误中的这一行:

serv1:RSA身份验证失败:无法加载公钥.

告诉我你的程序正在尝试自动登录,当你需要密码登录时,这不是你想要做的.

检查Perl/ssh文档:

identity_files

要在RSA/DSA身份验证中使用的RSA/DSA身份文件列表.此参数的值应该是对字符串数组的引用,每个字符串标识标识文件的位置.将针对服务器测试每个身份文件,直到客户端找到成功进行身份验证的身份文件.

如果您不提供此功能,则RSA身份验证默认使用$ ENV {HOME} /.ssh/identity,而DSA身份验证默认为$ ENV {HOME} /.ssh/id_dsa.

您可以尝试设置identity_files为空数组,以查看是否强制它使用您提供的密码; 或者你可以继续设置公钥认证,如上面的链接.