Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make users who have been inactive for a long time log out automatically under Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to let users who are inactive for a long time log out automatically under Linux", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "how to let users who are inactive for a long time log out automatically under Linux".

Automatically log out inactive users after a period of time on Linux

There are three ways to do this. Let's look at the first method first.

Method 1:

Edit ~ / .bashrc or ~ / .bash_profile files:

$vi ~ / .bashrc

Or

$vi ~ / .bash_profile

Add the following line to it:

TMOUT=100

This allows the user to log out automatically after 100 seconds of stopping the action. You can define this value as needed. Save and close the file.

Run the following command for the changes to take effect:

$source ~ / .bashrc

Or

$source ~ / .bash_profile

Now leave the session idle for 100 seconds. After 100 seconds of inactivity, you will see the following message, and the user will automatically exit the session.

Timed out waiting for input: auto-logoutConnection to 192.168.43.2 closed.

This setting can be easily modified by the user. Because the ~ / .bashrc file is owned by the user.

To modify or delete the timeout setting, simply delete the line added above and execute the source ~ / .timeout command to make the change take effect.

In addition, the user can also run the following command to prevent timeouts:

$export TMOUT=0

Or

$unset TMOUT

If you want to prevent users from changing this setting, use the following method instead.

Method 2:

Log in as the root user.

Create a new file called autologout.sh.

# vi / etc/profile.d/autologout.sh

Add the following:

TMOUT=100readonly TMOUTexport TMOUT

Save and exit the file.

Add executable permissions to it:

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

Now, log out or restart the system. Inactive users will automatically log out after 100 seconds. Ordinary users cannot modify the configuration even if they want to keep the session connection. They will be forced to exit in 100 seconds.

Both methods apply to both local and remote sessions (that is, users logged in locally and users logged in through SSH on remote systems). Let's take a look at how to automatically log out only inactive SSH sessions, not local sessions.

Method 3:

In this way, we will only allow SSH session users to log out automatically after a period of inactivity.

Edit the / etc/ssh/sshd_config file:

$sudo vi / etc/ssh/sshd_config

Add / modify the following lines:

ClientAliveInterval 100ClientAliveCountMax 0

Save and exit the file. Restart the sshd service for the changes to take effect.

$sudo systemctl restart sshd

Now, log in to the remote system through ssh. After 100 seconds, the ssh session will automatically close, and you will see the following message:

$Connection to 192.168.43.2 closed by remote host.Connection to 192.168.43.2 closed.

Now, anyone who logs in to this system through SSH from a remote system will automatically log out after 100 seconds of inactivity.

The above is about the content of this article on "how to make users who are inactive for a long time log out automatically under Linux". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report