• 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
    # 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

    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
    # 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

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

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

    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.

    Follow the below links for more tutorials

    How to find the path of any command in Linux
    How to configure a Clustered Samba share using ctdb in Red Hat Cluster
    How to delete an iscsi-target from openfiler and Linux
    How to perform a local ssh port forwarding in Linux
    How to use yum locally without internet connection using cache?
    What is umask and how to change the default value permanently?
    Understanding Partition Scheme MBR vs GPT
    How does a successful or failed login process works in Linux
    How to find all the process accessing a file in Linux
    How to exclude multiple directories from du command in Linux
    How to configure autofs in Linux and what are its advantages?
    How to resize software raid partition in Linux
    How to configure Software RAID 1 mirroring in Linux
    How to prevent a command from getting stored in history in Linux

    Deepak Prasad

    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?

    Become an author and be a part of our GoLinuxHub Team, 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.