Limit User Session Time in Lubuntu

Background

I have a young daughter who likes to take a turn playing on the computer, but it was nearly impossible to get her off the computer once she was on. I needed an easy way for her to learn when her session was over and it was time to log off. So I started a search on the web, which is what I would always do when I had a question.

Instead of any easy answer I found very little information on what it was I wanted to do. I did find a few other people asking similar questions but no answer that worked for me. I tried the timeoutd dameon and the PAM (which is Pluggable Authentication Modules for Linux) but neither of them seems to work, and it didn't look like they did quite what I wanted anyway.

I looked harder, the closest I found to an answer was a forum suggestion to write a bash script using sleep. I have written simple bash scripts in the past so I thought why not give this a try since nothing else was working.

Scripting

First thing need was to find out what commands I needed and how they worked. I found that in a terminal window sleep 30 && killall -9 lxsession would close the current session in 30 seconds.

Therefore my basic script ended up being:

#!bin/bash
sleep 30m
killall -9 lxsession

Name the script file something easy to remember like mine is: logout.sh . Save the file in a location that is easy to access also. I chose to keep the file in my Documents folder since then I am easily able to edit it at any time. Please remember if doing this, to change the group to something the person whose session your limiting is in. Or you can change the group to users which everyone should be in. You need to call the script at log in for it to actually be active for anyone.

Calling the script

I am using Lubuntu, which uses LXDE, and there will be some differences when using Gnome, KDE, xfce, etc. For my system I need to put a .desktop file in her /.config/autostart folder. She didn't have an autostart folder so I created it in /home/<user>/.config .

The logout.desktop I used goes like:

[Desktop Entry]
Encoding=UTF-8
Name=Auto Log Off
Comment = Will automatically log individual off after a set period of time
Exec=/home/<user>/Documents/logout.sh
Terminal=true

Please remember where the <user> is to place the correct username or use the correct path to where you placed the script.  And it’s as simple as that to have my daughter’s computer session closed 30 minutes after she logs on.

In closing

A few words about my choice of using killall -9 lxsession instead of something else. I could have used the lxde-logout but that would have only brought up the log out screen which if she hit cancel she would still be on the computer until she logged out or mom logged her off. Sure I could have used a command that would have searched for the PID and then killed the session using the PID but since only one person is logged into the computer at a time, the killall was just an easier way to my way of thinking.

Now this is a very simple way to handle logging her out, it’s not fancy but it does the job, and does it well. It currently doesn’t give her a warning that she’s going to be logged out, which is something that could easily be changed. I currently don't have a need to do so, but I may in the future.


Comments 1 comment

Mazmot 3 years ago

I had the same problem with my 10 year old son and searched to find your blog. It helped me a lot and I posted an entry about it in my Japanese blog (I think you will not read Japanese articles, but here is the address: http://ubun2.d-lights.jp/article/376788209.html ). I wrote basically the same thing as your blog entry, but I added two more scripts. One is to warn the user before the auto-logout starts for him/her to save important data. The other is make her/him not to use the PC after 8:00 p.m. It works for my kid. Thank you for sharing your experience.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working