How Do I Keep an SSH Session Alive?
Scenarios
This section describes how to keep an SSH session being connected to an ECS running CentOS 6.5.
The method described here applies to ECSs running CentOS or EulerOS.
Restarting sshd in the following procedure will disconnect SSH sessions.
Procedure
Modify the /etc/ssh/sshd_config file to keep an SSH session alive.
- Add the following configuration items to the /etc/ssh/sshd_config file:
ClientAliveInterval 600 ClientAliveCountMax 10
ClientAliveInterval 600 indicates that the ECS sends a request to the SSH client every 600 seconds to keep the SSH connection alive.
ClientAliveCountMax 10 indicates that the ECS automatically disconnects from the client if the client does not respond for 10 times after the ECS sends requests.
In such a case, the unresponsive SSH client will be disconnected after approximately 6,000 seconds (600 x 10).
ClientAliveInterval is a timeout interval in seconds. If the ECS receives no data from the client within the timeout interval, the ECS will send a message through the encrypted channel to request a response from the client. The default value is 0, indicating that these messages will not be sent to the client. The ClientAliveInterval option applies to SSH protocol version 2 only.
ClientAliveCountMax specifies the number of client active messages which may be sent when the sshd service does not receive any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session.
The use of client alive messages is very different from TCPKeepAlive. The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable.
- Run the following command to restart sshd for the configuration to take effect:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot