Operating System - Linux
1753768 Members
4962 Online
108799 Solutions
New Discussion юеВ

Re: how to set ssh timeout

 
SOLVED
Go to solution
K.C. Chan
Trusted Contributor

how to set ssh timeout

All,
I am having trouble executing remote command via ssh because it takes a long time to timeout if for some reasons there is a network issue during the middle or initial login process. Is there an option to tell ssh to timeout after so many seconds has passed if I don't get a response from it? Thanks.
Reputation of a thousand years can be determined by the conduct of an hour
6 REPLIES 6
Rick Garland
Honored Contributor

Re: how to set ssh timeout

In the /etc/ssh/sshd_config file is a LoginGraceTime. On my system is commented out. You can put in a value and remember to stop/restart the ssh daemon after making the change.
K.C. Chan
Trusted Contributor

Re: how to set ssh timeout

guys I am looking for something similar to rsync 's --timeout options. I am wondering if something like this is availabe with ssh from the client perspective. Thanks.
Reputation of a thousand years can be determined by the conduct of an hour
Ermin Borovac
Honored Contributor

Re: how to set ssh timeout

Two client side options introduced in ssh 3.8 may be what you are looking for.

ServerAliveInterval
ServerAliveCountMax

If ServerAliveInterval is set to 15 and ServerAliveCountMax is set to 3 and if the server becomes unresponsive ssh will disconnect after 45 seconds.

man ssh_config for more information (only on 3.8 or later).
Fred Ruffet
Honored Contributor

Re: how to set ssh timeout

Options given by Ermin are good. If you want to pass them onyour command line (no change to client default conf) you can use the -o option of the ssh command.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
K.C. Chan
Trusted Contributor

Re: how to set ssh timeout

This looks good. But one thing that is not clear, does both end (sshd and ssh client) have to be at ssh version 3.8 and later?
Reputation of a thousand years can be determined by the conduct of an hour
Ermin Borovac
Honored Contributor
Solution

Re: how to set ssh timeout

From what I can see only client needs to be at 3.8 or higher.

To test it out you can do the following

client$ ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=3 server

On the server find pid of sshd corresponding to this connection and send it STOP signal.

server# kill -STOP

Client should terminate connection after 45 seconds.