How to automatically log out of Linux shell with TMOUT

Estimated reading: 3 minutes 142 views

I. Introduction

Surely in the process of using VPS, you have SSHed into the VPS many times but have not been able to perform any administrative operations or run any commands. For some reason such as you forgot to exit the command line window, or you have an urgent business to go somewhere but can’t exit (This case can be called ‘session inactive’).

And of course this can bring some security risks, especially when you are logged in as root and surrounded by many people, then they can sabotage your VPS or insert Malware into your VPS. you in the simplest and fastest way.

Therefore, it is necessary to have a certain solution to be able to handle the problem when encountering the above cases. And one idea to deal with this is to configure it so that the system will automatically log out in the event of an inactive session. And to do that, we will use a variable named  TMOUT . And specifically how to do it, please see below.

II. Implementation Guide.

To configure  TMOUT  , you can follow these 2 steps.

Step 1: SSH into your server

First you need to SSH into your VPS with Root privileges, if you don’t know how to SSH, you can see the instructions below.

Step 2: Activate TMOUT

To enable  TMOUT  for all users in the system, you need to set the above variable in the profile file . You open the file according to the command below.

vi /etc/profile

 

Then you add the TMOUT variable as follows.

TMOUT=60
read only TMOUT
  output TMOUT

 

Automatically log out of the Linux shell with TMOUT

The number 60 here is the number of seconds that the system will automatically log out (you can replace it with the number of seconds you want), ie after 60 seconds if you do not have any operations on the VPS, the system will automatically log out.

In this configuration section, if you only need to configure a specific user, you can configure them in their  ~/.profile file  . If you want to disable TMOUT, you just need to delete the TMOUT variable or set the number of seconds to zero.

After editing, you need to run the command below to update the configuration.

source ~/.bash_profile

After the configuration is complete, please try to check if TMOUT is working by not doing anything on the VPS according to the time interval you configured. Like here, after 60 seconds of not doing anything, the system was automatically logged out .

How Do I Disable TMOUT?

To disable auto-logout, simply set TMOUT to zero or unset it as follows:
export TMOUT=0
or
unset TMOUT
Please note that read-only variables can be disabled by the root user in /etc/profile or ~/.bash_profile .

III. Summary

As such, in this article, We have shown you how to set up Auto Sign Out of Linux Shell using TMOUT on a complete Linux server with just a few simple commands. This setup seems simple, but it will definitely help you in some cases of negligence in the process of using and administering VPS, in order to protect VPS against bad guys who intend to destroy VPS. Hope this article helps you set up successfully.!

If you find the article useful, please share it widely so that everyone knows how to install it

Leave a Comment