Home Linux ServerLinux Fundementals Automatically logout of Linux Shell with TMOUT

Automatically logout of Linux Shell with TMOUT

by
Published: Last Updated on
A+A-
Reset

Automatically log out of Linux Shell with TMOUT with just a few simple steps with AZDIGI.

I. Introduction

Surely in the process of using VPS, you are or have been many times SSHing into VPS but not performing administrative operations or running any commands. For some reason, you forgot to exit the command line window or have an unexpected job to go somewhere without time to exit (this case can be called an “idle session”).

And of course, this can bring some security risks, especially when you are logged in as root and many people around you can simply sabotage your VPS or insert Malware into your VPS.

Therefore, there must be 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 case an idle session occurs. And to do that, we will use a variable named TMOUT. And in detail on how to do it, please see below.

II. Implementation guide

To configure TMOUT, you can do the following 2 steps.

Step 1: SSH into your server

First, you need to SSH into your VPS as root, if you don’t know how to SSH, you can see the instructions below:

Step 2: Enable 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 with the command below:

AZDIGI Tutorial
vi /etc/profile
    

Then you add the TMOUT variable as follows:

AZDIGI Tutorial
TMOUT=60
    
Automatically logout of Linux Shell with TMOUT

The number 60 here is the number of seconds that the system will automatically log out (you can replace the number of seconds you want), meaning that 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, just delete the TMOUT variable or set the number of seconds to 0.

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

AZDIGI Tutorial
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.

Automatically logout of Linux Shell with TMOUT

III. Summary

Thus, in this article, AZDIGI has shown you how to automatically log out of Linux Shell with TMOUT on a Linux server, complete with just a few simple commands. This setup will help you in some cases of negligence in using and administering VPS in order to protect VPS against bad guys who intend to destroy VPS. Wishing you success!

If you need assistance, you can contact support in the ways below:

5/5 - (1 vote)

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign