Auto Logout in Linux Shell Using TMOUT Shell Variable

When using a Linux shell, it's essential to ensure that users are logged out when they are not actively using the system to maintain security and efficiency. This can be achieved by setting an automatic logout timer using the TMOUT shell variable. In this article, we will explore how to set up auto logout in Linux shell using TMOUT, its benefits, and how to modify the settings.

What is TMOUT Shell Variable?

TMOUT is an environment variable in Linux shell that defines the number of seconds a shell session can be idle before it is automatically logged out. When this variable is set, the shell will terminate the session if there is no input activity for the specified time. This feature ensures that the system remains secure and prevents users from wasting system resources by staying logged in when inactive.

Setting Up Auto Logout Using TMOUT

Setting up the TMOUT shell variable is a simple process that requires modifying the user's shell configuration file. In most Linux distributions, this file is either ~/.bashrc or ~/.bash_profile.

Step-by-Step Configuration

Open your shell configuration file using a text editor

$ nano ~/.bashrc

Add the following line to set the TMOUT variable to your desired value (in seconds)

TMOUT=600

In this example, TMOUT is set to 600 seconds, meaning the shell session will automatically terminate after 10 minutes of inactivity.

Save the changes and exit the text editor. To apply the changes, source the shell configuration file

$ source ~/.bashrc

After completing these steps, the TMOUT shell variable will be active, and the shell will automatically log out the user after the specified period of inactivity.

Benefits of Auto Logout Using TMOUT

Enhanced Security

An idle shell session poses a security risk as it can be hijacked by malicious users. By setting up the TMOUT variable, you ensure that your system remains secure by automatically logging out idle users.

Resource Optimization

When users remain logged in without actively using the system, valuable system resources are wasted. The auto logout feature ensures optimal resource utilization by freeing up system resources when users are inactive.

Increased Productivity

Automatic logout after inactivity forces users to re-authenticate, serving as a reminder about system resource usage and encouraging efficient system utilization.

Modifying TMOUT Settings

You can easily modify the TMOUT settings to meet specific requirements. Open your shell configuration file

$ nano ~/.bashrc

Modify the TMOUT value to your desired timeout (in seconds)

TMOUT=1200

This example sets TMOUT to 1200 seconds (20 minutes). After saving and sourcing the file, the new timeout value becomes active.

Common TMOUT Values

Time Duration TMOUT Value (seconds) Use Case
5 minutes 300 High-security environments
10 minutes 600 Standard office environments
30 minutes 1800 Development environments
1 hour 3600 Long-running tasks

Disabling TMOUT

To disable the TMOUT variable, remove the TMOUT line from your shell configuration file or set it to zero

TMOUT=0

Alternatively, you can temporarily disable TMOUT for the current session

$ export TMOUT=0

Best Practices and Considerations

Data Loss Prevention TMOUT can cause data loss if users are working on tasks that exceed the timeout period. Consider providing users with commands to temporarily extend their session timeout when needed.

User Communication Clearly communicate the automatic logout policy to users, including the timeout duration and potential risks. Provide guidance on working within the policy limits.

System-wide vs User-specific TMOUT can be set system-wide in /etc/profile or per-user in individual configuration files. Choose the appropriate scope based on your security requirements.

Conclusion

The TMOUT shell variable is an essential security feature that enhances system protection by automatically logging out idle users. It optimizes resource usage and helps maintain system efficiency. While simple to implement, careful consideration should be given to timeout values and user workflows to balance security with productivity.

Updated on: 2026-03-17T09:01:38+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements