Reputation: 167
I'm connecting to a remote server using Net::OpenSSH.
my $ssh = Net::OpenSSH->new(
$server,
user => $user_name,
passwd => $password,
strict_mode => 0,
master_opts => ['-v']
);
This hangs when the authentication fails/when a wrong password is specified.
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
It's hanging in the above line.
Setting "$Net::OpenSSH::debug=-1;" returns:
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
How to make it exit in such case?
Upvotes: 1
Views: 1214
Reputation: 3842
As from the module documentation here is the way of handling errors:
my $ssh = Net::OpenSSH->new($host);
$ssh->error and
die "Couldn't establish SSH connection: ". $ssh->error;
Upvotes: 1