How do you disconnect inactive user sessions?

One of our regular reader hall sends an interesting question:

I work for a small company and most user login to centralized Linux server. I’d like to
automatically log out all inactive users from server for various reasons. How do I disconnect inactive user sessions?

To be frank, I don’t have any clear cut answer to question. There are at least 4-5 shells installed on a typical Linux installation. Also most user have has control over their own environment and user can switch to a different shell.

I hope our reader or seasoned UNIX admin can help to answer this question. Please share the experiences and advice in the comments.

Update: Checkout answer below in comments!

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • dave Jul 8, 2007 @ 18:22

    Hey I just added three of your articles to fsdaily.com which is a site like digg but for news and article about free software.

    Can you please add an “FSD it” link to your list of service links? It’ll make it easier for me (or anyone else) to do it with future articles you write.

    The link for this article would be:

    URL

    Thanks.

  • BOK Jul 6, 2007 @ 11:34

    Another way: for bash and Korn-shell, setting
    TMOUT=7200
    in /etc/profile will logout users after 2 hours of inactivity.

  • Oded Maimon Jul 6, 2007 @ 6:49

    you can do this in sshd_config file:

    Set idle session timeout to 15 min:
    ClientAliveInterval 300
    ClientAliveCountMax 3

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.