Help Center/ Huawei Cloud EulerOS/ FAQs/ How Do I Set Auto Logout Using TMOUT?
Updated on 2025-09-04 GMT+08:00

How Do I Set Auto Logout Using TMOUT?

Scenarios

To ensure system security and reduce resource waste, users must log out they are not actively using the system. This can be achieved by setting an automatic logout timer using TMOUT.

TMOUT is an environment variable in Linux shell that defines number of seconds a shell session can be idle before it is automatically logged out. When this variable is set, shell will terminate session if there is no input activity for set time. If this variable is not set or is set to 0, automatic logout is disabled, and users are not disconnected due to long-time inactivity.

Temporary Auto Logout Time

  1. Check the automatic logout time (the value of TMOUT):
    echo $TMOUT

    If no value is returned, TMOUT is not configured.

  2. Configure the automatic logout time for the current session.
    export TMOUT=seconds

Permanent Auto Logout Time

Method 1

Run the following command to modify the /etc/profile file. If the modification does not take effect, modify the /etc/bashrc file. The modification steps are the same. In this way, the automatic logout time will be configured for all users who use the configuration file.

vim /etc/profile

Or

vim /etc/bashrc

Add the following command to the end of the file: For example, you can set the automatic logout time to 1,200 seconds. If the value is set to 0, automatic logout will be disabled.

export TMOUT=1200
Figure 1 Configuring the automatic logout time

Save the file and run the following command to refresh the file:

source /etc/profile

Method 2

Run the following commands in sequence to change the automatic logout time:

sed -i '$a\export TMOUT=1200' /etc/profile
source /etc/profile
Check the automatic logout time:
echo $TMOUT

If the defined value is displayed, the automatic logout is configured successfully.

Figure 2 Successful configuration of automatic logout