• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to auto logout(timeout) a normal user and root user in Linux?

    Below steps are validated on Red Hat Enterprise Linux 7.

    Auto-logout functionality is mostly used to logout a user if the session is idle for a while. Using this article you should be able to set different timeout values for individual user in your Linux setup.

    To only disable a root user, create a log-out.sh script inside /etc/profile.d (The script name can be anything, log-out-sh is just a demo script name)
    # touch /etc/profile.d/log-out.sh

    # cd /etc/profile.d

    # vi log-out.sh
    #!/bin/bash
    # Log out in 2 minutes if the session is idle
    export TMOUT=120
    readonly TMOUT

    Here we are setting the variable as readonly. The TMOUT variable terminates the shell if there is no activity for the specified number of seconds (for us 120). You can change the limit as per your requirement.





    Log out and login using a new session to validate the new config
    [root@localhost ~]# echo $TMOUT
    120

    So above new value is set properly, and after waiting for 2 minutes the shell logs me out automatically
    [root@localhost ~]# timed out waiting for input: auto-logout
    [deepak@localhost ~]$

    NOTE: The above values can also be directly added to /etc/profile but that is not a recommended procedure.

    How to add different auto logout time value to individual users?


    I want my root user sessions to logout automatically after 2 minutes if idle and my normal user "deepak" to logout after 1 minute for idle sessions.

    To achieve this modify your log-out.sh script as below
    #!/bin/bash
    # Log out in 2 minutes if the session is idle
    if [ `id -nu` == "
    root" ];then
       
    export TMOUT=120
       readonly TMOUT
    elif [ `id -nu` == "deepak" ];then
       export TMOUT=60
       readonly TMOUT
    fi




    Log out and re-login to validate your new changes
    [deepak@localhost ~]$ echo $TMOUT
    60

    [deepak@localhost ~]$ su -
    Password:
    Last login: Sun Sep  3 16:51:40 IST 2017 on pts/1
    [root@localhost ~]# echo $TMOUT
    120

    As you see I have different values for different user. You can modify your log-out.sh script similarly to add more users with their respective timeout values

    I hope the article was useful.

    Deepak Prasad

    is a techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+


    Do you also have something to share here?
    Join GoLinuxHub Team as an Author, Click here for more information
    How to auto logout(timeout) a normal user and root user in Linux? How to auto logout(timeout) a normal user and root user in Linux? Reviewed by Deepak Prasad on Sunday, September 03, 2017 Rating: 5

    No comments:

    Powered by Blogger.