Configure Keep Alives on SSH Server in Linux

This article goes over how to configure your SSH server to make sure keep alives are active on the server. This applies to Linux Cloud and Dedicated solutions. 

  1. Open /etc/ssh/sshd_config in your favorite text editor (e.g., vi, vim, nano)
  2. If there is already not a line with the ClientAliveInterval option, add it to the bottom of the fille. Here is an example: ClientAliveInterval 600. This will send a keep alive message to the client if it has not received SSH communication after 600 seconds. This keep alive is sent through the already established, encrypted connection. Hosting.com recommends configuring SSH with this value if you require SSH connections to remain open between your SSH cilent and server machines.
  3. You can also configure the max amount of messages to sent the client using ClientAliveCountMax. The default value is 3. For example, if you leave it at default, and use the example above, it would take 1800 seconds for the client to be disconnected. You can think of it like this:
    1. Disconnect Client After Inactive for this many seconds = ClientAliveCountMax * ClientAliveInterval
  4. You may also wish to configure a  TCPKeepAlive value. An example would be something likeTCPKeepAlive Yes. This will send a TCPKeepAlives to the client machine. This should be setup if you're having issues with inactive SSH sessions that have been idling around for long periods of time. These sessions leave ghost users and consume server resources.
  5. Lastly, TCPKeepAlives are spoofable. This means you should lock down your system if you plan to use them, or malicious users can penetrate your system and cause your SSH connections to seem flaky. If you notice random disconnects in SSH, try disabling TCPKeepAlives and rely more on ClientAlive values in your SSH server configuration.
  6. The SSH server should be restarted after these settings are changed to take effect
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Installing htop

htop is an interactive process viewer for Linux, which is a powerful alternative to the...

Bind Multiple IP Addresses to a Single Network Interface Card (NIC)

This tutorial demonstrates how to bind multiple IP addresses to a single NICI'll be using LAN...

Clear Memory Cache on Linux Server

By default the Linux OS has a very efficient memory management process that should be freeing any...

Set the time on a Linux server

Log into the server via SSHAt the shell prompt run the following command:date MMDDHHmmYYYYFor...

Check your disk usage in Linux

A good way to check your disk usage for folders on your Linux server is via shell.Download...