In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve automatic logout function for users who are inactive for a period of time on Linux, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.
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 all the contents of this article entitled "how to enable users who are inactive for a period of time to log out automatically on Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.