How to Enable Automatic Logout for SSH?

SSH (Secure Shell) is a cryptographic network protocol that provides a secure connection between devices. One way to improve the security of an SSH connection is to configure automatic session logout after a certain period of inactivity. In this article, we will look at how to enable automatic logout for SSH on your server.

To enable automatic logout for SSH, you will need to edit the SSH configuration file on your server. Let’s break down how to do this step by step.

Step 1: Open the SSH Configuration File

Open the terminal and enter the following command to edit the SSH configuration file:

$ sudo nano /etc/ssh/sshd_config

Enter the administrator password when prompted. This command will open the SSH configuration file in the nano text editor.

Step 2: Find and Edit the ClientAliveInterval Parameter

Use the arrow keys on your keyboard to scroll through the SSH configuration file and find the ClientAliveInterval parameter. This parameter specifies the time interval (in seconds) after which the SSH server will check the client’s activity.

Uncomment (remove the # symbol at the beginning of the line) and edit this parameter according to your requirements. For example, to set the interval to 300 seconds (5 minutes), change the line to:

ClientAliveInterval 300

Step 3: Add the ClientAliveCountMax Parameter

Now add the ClientAliveCountMax parameter, which specifies the maximum number of checks within the ClientAliveInterval before the session is terminated. Find the line with this parameter and edit it to suit your needs. For example:

ClientAliveCountMax 3

This means that the session will be terminated after 3 failed check attempts.

Step 4: Save and Close the SSH Configuration File

Save the changes by entering Ctrl + O and close the nano editor using the key combination Ctrl + X.

Restart the SSH service to apply the changes, using the following command:

$ sudo systemctl restart sshd

Now automatic logout for SSH on your server should be successfully enabled. Check the correctness of the settings by logging into SSH and waiting for the automatic logout after the specified interval.

We hope this article has helped you configure a secure SSH connection on your server. Follow the instructions and don’t forget about network security!