Access to our computer (not only to the internet) needs to be restricted for the accounts of my kids (7, 8) until they are old enough to manage this by themselves. Until then we need to be able to define the following:
- the hours of the day when computing is o.k. (e.g. 5 - 9 pm)
- the days of the week when computing is not o.k. (e.g. mondays to fridays)
- the amount of time allowed per day (e.g. 2 hours)
In 11.10 all of the following that used to do the job don't work any more:
- Timekpr: for > 11.10 no more available through the ppa.
- Timeoutd: command line alternative, but from 11.10 removed from the repositories.
- Gnome Nanny: Looks great but repeatedly crashes to force restarting X-server. So we can't use or recommed this program at the moment.
Are there any other alternatives?
Ubuntu <= 11.10 User's follow this guide for Ubuntu User's >= 11.10 read the Bottom page notice :
Yes all of those programs are out of date and all your questions are answered here and good look with your parent control.....
When we talk about forcing a user to log off, what we’re really talking about is implementing time restrictions on the account for system access or services. The easiest way I’ve found to implement time restrictions is using a plug-in module called Linux-PAM.
Pluggable Authentication Module (PAM) is a mechanism for authenticating users. Specifically, we’re going to use the
pam_time
module to control timed access for users to services.Using the
pam_time
module, we can set access restrictions to a system and/or specific applications at various times of the day as well as on specific days or over various terminal lines. Depending on the configuration, you can use this module to deny access to individual users based on their name, the time of day, the day of week, the service they’re applying for, and their terminal from which they’re making the request.When using
pam_time
, you must terminate the syntax of each line (or rule) in the/etc/security/time.conf
file with a newline. You can comment each line with the pound sign [#], and the system will ignore that text until the newline.Here’s the syntax for a rule:
Here’s an example of a typical set of rules:
These rules restrict user bobby from logging on between the hours of 0800 and 2000, and they also restrict Internet access during these hours. Root would be able to logon at any time and browse the Internet during all times as well.
Note: The system logs errors with these rules as syslog(3).
With Ubuntu Linux, it is possible to assign to your computer time restrictions, to prevent the connection of one or more users to your system. With the time restrictions, you can, for example, limit access to the computer for your children (a kind of parental control, in short), or even protect the connection to your server during certain hours.
Manual Configuration
Understand what you will do
Throughout this tutorial, we will use PAM (Pluggable Authentication Modules, English Pluggable Authentication Modules). It allows you to control user authentication when they connect. Then, we will use the security configuration files to define logon hours allowed. These manipulations can be performed on any version of Ubuntu, and require only a simple text editor (vim, emacs, nano, gedit, kate, to name a few). Enable Restrictions hours via the PAM Module
First of all, first go to the
/etc/pam.d/
, where is all configurable services:If we want to block the connection to the computer, we will have to change the gdm service. Edit the file so gdm and add this line of code (at the end of file):
GDM is the login screen distributions Ubuntu, Edubuntu and Xubuntu. For Kubuntu, which uses KDE, kdm service is called, it will be the file it will open. And you're done for configuring the PAM! This will enable the control of hours on this service.
If you have a server, you probably do not have no GUI. In this case, GDM / KDM not installed and the connection will not be blocked. To prevent connection to TTY, you must modify the login of the same file, and add the same line of code than previously acknowledged. This action also applies to people who have installed a GUI and want to block access to the login screen and terminals.
Configure Access Hours
Now that the PAM service has been activated, we only have to configure access times. Open the
/etc/security
. Several configuration files are available:Edit the file
time.conf
. Some explanations and examples (English) introducing the. To set access schedules, copy and paste the following line of code (at the end of the file, as always):Instead of the user field, enter the login account you want to block.
If you want to block multiple users, enter their login in a row, separated by the | operator. For example, if I want to freeze the accounts of Patrick, John and Emily:
By cons, if you want to block access to the system for all users but one in particular, use the! before the person concerned. For example, if I want access to the computer is denied to all users, except Nicolas and Xavier:
Turning now to the field zones. In this field that the selection of days and hours will be allowed connection possible. You must first specify the day of the week, using the following abbreviations:
Be careful not to confuse the abbreviations Wk and Wd are misleading! particularly poorly identified on the Internet: you can easily find conflicting information!
Then, we specify the deadlines. These should be formatted 24H, consisting of 4 digits. For example, to restrict 3:17 p.m. to 6:34 p.m., we write: 1517-1834. To allow Marie to connect only on Tuesday, from 3:17 p.m. to 6:34 p.m., we obtain the result:
Connections outside of these hours will be banned. As for users, it is possible to use the operators | and! to indicate several times (the! then indicate that all logon hours are allowed, except those to be shown).
The two stars (wildcards) at the beginning of the line of code are, respectively, and tty services fields. Since you want to block all access to the system, it is unnecessary to specify what service or what tty you want to block. However, if you want to prevent the use of a particular service, simply specify it as the following example:
Thus, the user marry can not connect to a TTY, 4 and 5 during the weekend.
Some Examples of Restrictions Schedule
mathilde is allowed to connect every day from 1:20 p.m. to 3:20 p.m. and from 4:00 p.m. to 8:30 p.m.:
Stone, Frank and Florian are allowed to connect to 2:00 p.m. to 6:45 p.m. during the weekdays, and 2:00 p.m. to 10:15 p.m. for the weekend:
Olive is never allowed to connect. jessica can log on Wednesday from 1:00 p.m. to 4:00 p.m.:
2 different lines, for two different time for each user Expiration of a Session
When a session expires (it exceeds the time while the user is already connected), the PAM can reach the user. While mathilde connects during the hours of time allowed, it is perfectly free to exceed these hours! For this, we will use a new program: ´cron´. This application executes commands at intervals of time. In our case, we will make use of command ´skill-KILL-u´ to disconnect the user when the session expires. Handling is very simple. Simply edit the file ´/etc/crontab´. Then add the following line of code:
As before, replacing the Minute field schedules and time desired. Then fill in the day (s) by (s) day (s) banned (s), or simply type an asterisk (*) to indicate all days of the week. Finally, change the field used by the login account to be blocked, and voila!
Days do not notice the same way with the
cron
jobs! Here is the list of abbreviations to be used with this program:Some Examples of
cron
jobs (with examples of times in the previous section)jessica can log on Wednesday from 1:00 p.m. to 4:00 p.m.
mathilde is allowed to connect every day from 1:20 p.m. to 3:20 p.m. and from 4:00 p.m. to 8:30 p.m..
Stone, Frank and Florian are allowed to connect to 2:00 p.m. to 6:45 p.m. during the weekdays, and 2:00 p.m. to 10:15 p.m. for the weekend
The command skill-KILL-u disconnects the user from the GUI, as well as TTY. It is perfectly usable for server administrators. However, this command is immediate and the disconnection will be made without notice. It would therefore be preferable to prevent the installation of this device users of the computer or network in question!
It is possible to prevent users with a
wall
command launched bycron
few minutes before the end of the timeframe, that will be displayed in the terminals of all users.To prevent users from GUI can be used in place of the wall command
notify-send
is in the package libnotify-binUbuntu 11.10 User's
I've seen around user having problems with Pam and i saw alot of bug about that so Why is the reason??? is so simple Ubuntu 11.10 doens't support GDM anymore the new display manager is lightGDM the problem is the follow where store this directive
account required pam_time.so
i think is in/etc/pam.d/lightdm
or/etc/pam.d/lightdm-autologin
but bug how ???so for just around you can check this 2 LightGdm log files :
or run LightGdm in debug mode :
or report a bug :
I report the Bug's here so cross your finger and wait....
TimeKpr
I guess it has everything you need. Limit access time per day per user, easy gui for configuration, abitlity to bypass for a day, add some "reward time", notification of remaining time for users, etc.
The project page is here. They also have a PPA for ubuntu which you can add to your Software Sources:
deb http://ppa.launchpad.net/timekpr-maintainers/ppa/ubuntu lucid main
. And install via Software Center or via CLI:sudo apt-get install timekpr
.Auto-logoff is extremely frustrating if you are in the middle of something. It's violent, it's brutal, it's plain rude. And it doesn't matter how old you are. It's one thing when you are just computer addicted and it's very different when you are tracking time and get kicked out 5 seconds before you managed to click that submit button or save your document. I suggest you to consider using an auto-reminder instead of an auto-kicker. That will teach your kids to respect each other and allow each other to use the computer willingly.
There's even a lighter alternative. Start by tracking the amount of time that each kid spends using the computer and make the gathered data available for all of them so they can see it. This incredibly simple thing alone (applied to internet bandwidth spent) has saved my life when I was being the network admin in an office full of adults. The public stats about bandwidth usage for each computer (just the amount of bytes, not deanonymizing info like lists of visited sites etc) turned the situation from "me - the evil greedy admin against them - the poor abused office users" to "man, you downloaded 5 times more than me, that's bad!" "sorry, I downloaded indeed, I watched a lot of youtube during lunch breaks, won't do it anymore at this rate" - I was simply excluded from the confrontation scenario.
Timekpr
can be used in 11.10 running LightDM to setup restrictions for users by adding the following line to
/etc/pam.d/lightdm
We may need to remove libpam-smbpass to enable user switching until bug #835310 is fixed.
All restrictons defined in the application window work as defined in the timekpr GUI.
To display the timekpr-client icon in Unity we need to whitelist
'timekpr'
in Unity panel settings, and in addition we need to addUnity
to the following line in/etc/xdg/autostart/timekpr-client.desktop
:To start the countdown of the time granted we may have to start the timekpr daemon with
for 14.04:
A newer release/fork of timekpr was published for Ubuntu 14.04 by Eduards Bezverhijs in his
ppa:mjasnik/ppa
.I had this issue too. So I wrote the kidtimer script, which lets you define usage times and totals. The project can be found on Github at the following location:
This is how to install it and use it:
Copy and paste the code into a file called
kidtimer.install
.Execute it:
Run it:
Setup a existing user account.
Done.
For help:
Add time to a user's account (for that day only):
Features:
Key files:
Cronjobs:
Note:
The application uses
notify-send
to alert user time is running out. When time runs out, all user processes are terminated, so please prepare user.timekpr - This program will track and control the computer usage of your user accounts. You can limit their daily usage based on a timed access duration and configure periods of day when they can or cannot log in. With this application, administrators can limit account login time duration or account access hours. The application works as a parental time control, and will be useful to parents who want to limit child access time.
You can update your system with unsupported packages from this untrusted PPA by adding
ppa:timekpr-maintainers/ppa
to your system's Software Sources.This package is available in :
Hardy
What are PPAs and how do I use them?
PROBLEM :
I report the Bug's here so cross your finger and wait....
Introduction
We can check if a user is logged in by the command:
which gives us an output like:
In the output we get the pid of the targeted user, that needs to be halted if the time exceeds the limit.
The solution
Assuming your user does not have
sudo
privileges:This solution is a small background script. It limits the usage per day to a defined number of minutes, to set in the head of the script. Once set up (which is not too difficult) it runs very easy, and no additional action is needed afterwards.
To prevent unwanted data loss of possibly opened files, 60 seconds before the targeted user's time limit expires, a message will appear on his or her
DISPLAY
:The script
How to use
limit
limit_use
(no extension) inside the folder and make it executableEdit in the head of the script the user name to limit, and the maximum number of allowed minutes. In the example:
Copy the folder to the directory
/opt
:Now edit
/etc/rc.local
to make the script run it asroot
on startup:Just before the line
another line:
Explanation; how it works
/opt/limit/uselog
). If the daily limit is reached, the script no longer allows the user to be logged in, kills its process if it exists.rc.local
only user(s) with sudo privileges can stop the script, even then only if the user knows the process name.Stop the script
In case you'd like to stop the script, use the command:
But you'd need the sudo password to do so.
I tried
timekpr
but did not got it working. Then made a variant of it which works on my Ubuntu. This is what one needs to do for this variant:Add time limit in
/var/lib/timelimit/user_to_be_limited.limit
file with root rights only. e.g. 1800 for 1800 seconds (30 minutes) daily limit.Create
/usr/local/bin/timelimit.sh
with root rights with following:Add to
/etc/rc.local
:Restart Ubuntu
I just made an answer available easily. Code is explained on thread http://forums.linuxmint.com/viewtopic.php?f=213&t=77687 . In short: a limit configured in minutes per day, a cron job every minute, a message to user to keep him informed and a forced logoff.
To download and install this, open a Terminal and run the commands below:
Administrator password will be requested during the installation process (to install the cron job, to copy the script, …). From there you will be guided for all. There is also an ./uninstall.sh at the same place just in case. It is build to work with all Ubuntu based distro (Mint, etc… probably all debian also). If any issue occurs please let me know, including system version and graphical environment in comments:
Thomas Baeckeroot
Lock Screen Timer
Create your own Screen Lock Timer instead of 3rd Party applications
Although there are 3rd Party applications to do this, you can create your own. Summary of steps:
gedit
to create scriptlock-screen-timer
lock-screen-timer
lock-screen-timer
as an executableUse
gedit
to create scriptlock-screen-timer
Open the
Terminal
using Ctrl+Alt+T and type:Copy and paste code from window below to
lock-screen-timer
Toggle back to this screen and copy the following code by highlighting it and pressing Ctrl+C:
Then toggle back to the empty
gedit
window and paste the code using Ctrl+V. Save the file and exit the editor back to the command prompt.Mark
lock-screen-timer
as an executableNow we need to make the script executable by typing:
Test It!
Before calling the script from the GUI, we'll call it from the terminal so we can see if any error messages are displayed:
You are prompted for the number of minutes:
Set the desired number of minutes and click OK to start the timer. When there are 15, 10, 5, 3, 2 and 1 minute(s) left a system sound is heard and a message bubble appears advising when the screen will be locked. After the screen is locked you need to enter your password to unlock the screen.
Configure Nautilus to execute bash scripts
Nautilus defines what happens when we double click on an executable script when it's the files display window or a link on on the desktop. Normal behavior is to edit the script using
gedit
. We want to change this behavior such that it is executed.Start Nautilus and navigate to directory containing
lock-screen-timer
. Left click on it once to give it focus. Hover mouse over top menu bar until "File Edit..." menu appears, use:Edit
drop-down menuProperties
optionBehavior
tabExecutable Text Files
Run executable text files when they are opened
Create desktop shortcut link
From previous section
lock-screen-timer
still has focus. If not, navigate to the script and left click on it once to give it focus. Then use:Make Link
.Link to lock-screen-timer
.Now you can double click on the desktop shortcut link and the script is run. A dialog box appears to get the number minutes. Two buttons are presented Cancel and OK. If you click the
X
to close the window it is the same as selecting Cancel.After the timer is running and you double click on it again the first running copy is "killed". You can now start a new scren lock countdown or click Cancel for no countdown.
Display Time Remaining in systray / notification area
While lock screen timer is running it records how many minutes are remaining into the file
~/.lock-screen-timer-remaining
. You can look at this file with thewatch
command or display it on Ubuntu's system tray / application indicator bar as shown at the top of this answer. To display time remaining in the notification area, follow the instructions in this Q&A: Can BASH display in systray as application indicator?.