SSH connection timed out on network :: SSH :: Perl

I am using Net :: SSH :: Perl to connect to a remote server and execute commands. The problem is that it doesn't time out even if the remote server is unresponsive for a long time. In Net :: SSH :: Perl, I cannot find the timeout parameter.

Any help to achieve the timeout is appreciated.

Note. I don't have permission to change Net / SSH / Perl.pm

+3


source to share


3 answers


Use the parameter ConnectTimeout

.

Example:



use Net::SSH::Perl;

my %params = ( protocol => "2,1",
                identity_files => ["/home/user/.ssh/test_id_dsa"],
                options => [    "BatchMode yes",
                                "ConnectTimeout 3",
                                "StrictHostKeyChecking no"],
                debug => 'true'
);

      

Also see: Net :: SSH :: Perl ConnectTimeout (ssh -o option)

+3


source


As I can see from yours %params

, you are using a DSA key to authenticate to the remote server. Do you really need to use the built-in Perl SSH implementation that it provides Net::SSH::Perl

? This is useful in some cases where you can't just wrap a normal call ssh

(for example, if you need to provide a plain text password to connect to the server), but it doesn't have many useful SSH options - you've just found one of them.

I suggest you instead use Net::SSH

(which is a very simple wrapper for the binary ssh

) and give it the parameters ConnectTimeout

and ServerAliveInterval

with -o

or Net::OpenSSH

which @ChankeyPathak specified above and uses his method check_master

(as I understand from the description, it looks like what you need).

The manual ssh_config(1)

has a good description ConnectTimeout

(which defines the timeouts when establishing a connection) and TCPKeepAlive

and ServerAliveInterval

(which defines the timeouts on an established connection).



For reference: here is a complete list of options implemented in Net::SSH::Perl

, grabbed from it Config.pm

. If you need to use any other parameter not listed here, please use some other SSH module.

BindAddress
Host
BatchMode
ChallengeResponseAuthentication
Cipher
Ciphers
Compression
CompressionLevel
DSAAuthentication
GlobalKnownHostsFile
HostKeyAlgorithms
HostName
IdentityFile
NumberOfPasswordPrompts
PasswordAuthentication
PasswordPromptHost
PasswordPromptLogin
Port
Protocol
RhostsAuthentication
RhostsRSAAuthentication
RSAAuthentication
StrictHostKeyChecking
UsePrivilegedPort
User
UserKnownHostsFile

      

+2


source


I had a similar problem. I was running a command that didn't stop for whatever reason. So I wrapped the $ ssh-> cmd call in eval with an alarm, as described in perldoc -f alarm

. Not the nicest solution, but the only option as I can't change the command I was calling.

+1


source







All Articles