How to Work with SSH Timeout

When you log in to an SSH server using an SSH client, there is no time limit set in the SSH configuration file, which enables the session to be logged in for the maximum amount of time. We can set such a limit, so that the session expires after a specific period of time. This tutorial will show you how to setup a timeout value to an SSH session.

Step#1: Opening Configuration file

For the purpose of this tutorial, we are going to use the Ubuntu environment and will add the commands for SSH timeout in the configuration file.
First of all, let’s open up the “sshd_config” file in the graphical editor:

open the sshd_config file

Step#2: Editing Configurations

Next, let’s insert the “ClientAliveInterval” command over here and specify the number of seconds we want to set for the timeout. Let’s specify 25 seconds for now and just beneath that, let’s add a command that would allow the session to be terminated after the 25 seconds in case of no activity. For that, we will use the “ClientAliveCountMax” command and specify the value to zero.
With that done, save the file.

setting up configuration variables

Step#3: Implementing the Configurations

Finally, restart the host’s services by typing “service ssh restart” in the terminal.
Now let’s login to the server once more and wait for 25 seconds to see whether the session times out or not.
And there you have it. The session has been terminated automatically after 25 seconds, which means that the SSH timeout feature has been enabled in the configuration file successfully.

restart so that changes take effect