ssh connection timeout resolution

  • 2020-05-07 20:45:03
  • OfStack

1. Modify etc/ssh/sshd_config at the server end


ClientAliveInterval 60 #server every 60 Seconds to send 1 Requests for client And then client Response to maintain the connection 
ClientAliveCountMax 3 #server After the request is issued, the client does not respond to the number of times reached 3 , automatically disconnect. Under normal circumstances, client Don't fail to respond 

2. Modify etc/ssh/ssh_config on client to add the following :(without permission to change server configuration)


ServerAliveInterval 60  #client every 60 Seconds to send 1 Requests for server And then server Response to maintain the connection 
ServerAliveCountMax 3  #client After the request is issued, the server does not respond to the number of times reached 3 , automatically disconnect. Under normal circumstances, server Don't fail to respond 

Another way:
Do not modify the configuration file
In the command argument ssh-o ServerAliveInterval=60 this will only keep persistent connections as long as they are needed. After all, not all connections need to be persistent

Such as:
According to the first scenario, the modified ssh service needs to be restarted. OK:


PisOWebsv02:/etc/ssh # service sshd
Usage: /etc/init.d/sshd {start|stop|status|try-restart|restart|force-reload|reload|probe}
PisOWebsv02:/etc/ssh # service sshd restart
Shutting down SSH daemon                     done
Starting SSH daemon 


Related articles: