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

How Do I Set Auto Log 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.

Procedure

  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. To define a long-term automatic logout time, go to 3.
    export TMOUT=seconds
  3. Use this variable to set a long-time automatic 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, the automatic logout is disabled.

    export TMOUT=1200

    Save and then 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
  4. Check the automatic logout time:
    echo $TMOUT

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