无法使用Net :: SSH登录:Perl

时间:2015-08-07 23:05:57

标签: perl ssh

我刚开始使用Net :: SSH :: Perl,似乎我遇到了一些奇怪的东西。如果我将交互式标志设置为1并输入我的密码,我将通过ssh远程登录到机器,但如果我关闭交互式标志或将其设置为0,则登录失败。我确认我能够使用Net :: SSH :: Perl登录我的本地机器,因此它必须是我为这个特定的远程机器做错的事情,其中​​底层操作系统是SuSE。我还确认我能够从终端窗口ssh到远程机器。

use Net::SSH::Perl;
my $cmd = 'uptime';
my $ssh = Net::SSH::Perl->new($host, interactive=> 0, debug => 1);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print $stdout;

以下是交互标志设置为0时从调试输出的日志。

localhost.localdomain: Reading configuration data /home/user/.ssh/config
localhost.localdomain: Reading configuration data /etc/ssh_config
localhost.localdomain: Connecting to 1.1.1.1, port 22.
localhost.localdomain: Remote version string: SSH-2.0-OpenSSH_5.1

localhost.localdomain: Remote protocol version 2.0, remote software version OpenSSH_5.1
localhost.localdomain: Net::SSH::Perl Version 1.38, protocol version 2.0.
localhost.localdomain: No compat match: OpenSSH_5.1
.
localhost.localdomain: Connection established.
localhost.localdomain: Sent key-exchange init (KEXINIT), wait response.
localhost.localdomain: Algorithms, c->s: 3des-cbc hmac-sha1 none
localhost.localdomain: Algorithms, s->c: 3des-cbc hmac-sha1 none
localhost.localdomain: Entering Diffie-Hellman Group 1 key exchange.
localhost.localdomain: Sent DH public key, waiting for reply.
localhost.localdomain: Received host key, type 'ssh-dss'.
localhost.localdomain: Host '1.1.1.1' is known and matches the host key.
localhost.localdomain: Computing shared secret key.
localhost.localdomain: Verifying server signature.
localhost.localdomain: Waiting for NEWKEYS message.
localhost.localdomain: Send NEWKEYS.
localhost.localdomain: Enabling encryption/MAC/compression.
localhost.localdomain: Sending request for user-authentication service.
localhost.localdomain: Service accepted: ssh-userauth.
localhost.localdomain: Trying empty user-authentication request.
localhost.localdomain: Authentication methods that can continue: publickey,keyboard-interactive.
localhost.localdomain: Next method to try is publickey.
localhost.localdomain: Publickey: testing agent key 'user@localhost.localdomain'
localhost.localdomain: Authentication methods that can continue: publickey,keyboard-interactive.
localhost.localdomain: Next method to try is publickey.
localhost.localdomain: Publickey: testing agent key 'user'
localhost.localdomain: Authentication methods that can continue: publickey,keyboard-interactive.
localhost.localdomain: Next method to try is publickey.
Permission denied at /home/user/workspace/perl-random/avamar_ssh.pl line 4.

我猜我做错了什么,所以如果有人能指出正确的方向那就太棒了。

感谢。

1 个答案:

答案 0 :(得分:1)

这部分:

localhost.localdomain: Authentication methods that can continue: publickey,keyboard-interactive.

表示服务器允许两种方法进行身份验证:

  • publickey - 公钥验证
    • 你在评论中提到这不适合你。
  • keyboard-interactive - 您输入密码的位置
    • 这只能在交互模式下工作,这一点不足为奇。

所以,你想要做的事情是不可能的。

好消息是,这听起来像X-Y Problem。如果您向我们提供有关真实问题的更多详细信息,我们可能会建议更好的方法。