1

我正在使用 Net::OpenSSH 连接到远程服务器。

my $ssh = Net::OpenSSH->new(
              $server, 
              user => $user_name, 
              passwd => $password, 
              strict_mode => 0, 
              master_opts => ['-v']
);

当身份验证失败/指定错误密码时,这会挂起。

OpenSSH_6.0p1, OpenSSL 0.9.8d 28 Sep 2006
debug1: Reading configuration data /usr/software/etc/ssh_config
debug1: Connecting to 10.53.34.200 [10.53.34.200] port 22.
debug1: Connection established.
...
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password

它挂在上面的行中。

设置“$Net::OpenSSH::debug=-1;” 返回:

debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
# file object not yet found at /usr/hema/.libnet-openssh-perl/diag-10.53.34.200-21463-907722
# file object not yet found at /usr/hema/.libnet-openssh-perl/diag-10.53.34.200-21463-907722

在这种情况下如何让它退出?

4

1 回答 1

1

从模块文档这里是处理错误的方式:

my $ssh = Net::OpenSSH->new($host);
$ssh->error and
die "Couldn't establish SSH connection: ". $ssh->error;
于 2013-09-04T09:27:21.397 回答