Automatically log out inactive users after login timeout in Linux

Automatically log out inactive users after login timeout in Linux

Method 1: Modify the .bashrc or .bash_profile file

This can be achieved by modifying the .bashrc or .bash_profile file in the home directory. Choose one of the two files and add the following line at the end. The specific operations are as follows:

[GeekDevOps@GeekDevOps /]$ cd ~
[GeekDevOps@GeekDevOps ~]$ echo "TMOUT=90">>.bashrc 
[GeekDevOps@GeekDevOps ~]$ source .bashrc

In the above code, we selected the .bashrc file. If you choose .bash_profile, the operation process is the same. Above, we set the user's automatic logout time to 90 seconds. After 90 seconds, the screen will display as follows:

[GeekDevOps@GeekDevOps ~]$ Timeout waiting for input: Automatically log out Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(10.1.1.21:22) at 16:38:48.

Method 2: Implement by modifying the ssh configuration file

ssh is a tool that we often use in Linux systems. By modifying the ssh configuration file /etc/ssh/sshd_config we can also implement the timeout automatic logout function, as follows:

[root@GeekDevOps ~]# vim /etc/ssh/sshd_config

Find the following two lines:

#ClientAliveInterval 90
#ClientAliveCountMax 3

Remove the comments and modify the following numbers:

ClientAliveInterval 60
ClientAliveCountMax 5

After saving and exiting, restart the ssh service:

[root@GeekDevOps ~]# service sshd restart

This method will cause a 60-second login timeout for all users except root, and they will be automatically logged out. The first line indicates that the connection will be disconnected after 5 inactivity detections, while the second line indicates that the connection will be disconnected after 5 inactivity detections.

Method 3: Implement by modifying the ssh configuration file

In the /etc/profile file, add the TMOUT field and then source /etc/profile.

TMOUT=300
export TOMOUT

Method 4: Create a script

Log in as root and create a new file called autologout.sh.

vim /etc/profile.d/autologout.sh

Add the following content:

TMOUT=100
readonly TMOUT
export TMOUT

Save and exit the file, and give it executable permissions:

chmod +x /etc/profile.d/autologout.sh

Now, log out or reboot your system. Inactive users will be automatically logged out after 100 seconds. Even if ordinary users want to keep the session connection, they cannot modify this configuration and will be forced to log out after 100 seconds.

Summarize

The above is what I introduced to you about how to automatically log out inactive users after a login timeout in Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Play with the connect function with timeout in Linux
  • How to solve the timeout during pip operation in Linux
  • Connect timeout processing under Linux (summary)
  • Use Linux Shell script to handle MySQL timeout regularly

<<:  How to understand JavaScript modularity

>>:  Using MySQL database with Python 3.4 under Windows 7

Recommend

How to display a small icon in front of the browser URL

When you browse many websites, you will find that ...

MySQL 5.7.15 installation and configuration method graphic tutorial (windows)

Because I need to install MySQL, I record the ins...

MySQL 5.7.27 installation and configuration method graphic tutorial

MySQL 5.7.27 detailed download, installation and ...

Solution to the problem of installing MySQL compressed version zip

There was a problem when installing the compresse...

How to use Linux locate command

01. Command Overview The locate command is actual...

Solution to the ineffective margin of div nested in HTML

Here's a solution to the problem where margin...

Detailed analysis of the chmod command to modify file permissions under Linux

Use the Linux chmod command to control who can ac...

Vue implements a simple calculator

This article example shares the specific code of ...

Solve the error during connect exception in Docker

When you first start using Docker, you will inevi...

Docker container introduction

1. Overview 1.1 Basic concepts: Docker is an open...

How to dynamically add ports to Docker without rebuilding the image

Sometimes you may need to modify or add exposed p...

Solution to the MySQL error "Every derived table must have its own alias"

MySQL reports an error when executing multi-table...

Detailed process of changing apt source to Alibaba Cloud source in Ubuntu 18.04

Table of contents Preface: Ubuntu 18.04 changes a...