LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-08-2009, 10:02 AM   #1
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Lock desktop programmatically


Our little son is quickly becoming a computer addict, and that interferes with his obligatory piano lessons. In other words, as long as he has access to his computer the piana is gathering dust.

I would like to lock his GUI desktop by means of a program called from cron, or activated thru SSH if I have to do it on unscheduled moments.

I know that KDE has an option to lock the desktop, but then it can be unlocked with the normal user password, which isn't good either.

A more rigorous approach would be to close down the complete computer, but how do I then prevent it from starting again? I could disable his password on the server of the NIS domain to prevent him to login again, but I don't think this is a very elegant solution.

Any ideas? I speak Bash quite good and furthermore C, PHP and TCL/Tk, but no C++ or QT.

jlinkels
 
Old 07-08-2009, 12:15 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Here is my idea: put a script in root's crontab which kill the X session and lock the user, so that he cannot login back. Here is an example of what the script could be (assuming gnome as desktop manager but you can find similar commands for KDE):
Code:
#!/bin/bash
trap : HUP
count=10
( for i in $(seq 10 10 100)
do
  echo "# Closing in $((count--)) seconds"
  sleep 1
  echo $i
done ) | /usr/bin/zenity --auto-close --progress

/usr/bin/pkill -9 gnome-session
/usr/sbin/usermod -L username
This uses zenity to display a message and leave a bunch of seconds, so that your son can save any open file before leaving. Note the trap statement which is useful if the user click on the cancel button in the zenity dialog (which sends an hang-up signal and would stop the script execution).

Then you have to run a cron job as root, using the X display:
Code:
30 19 * * * env DISPLAY=:0 /root/script.sh
this assumes the current DISPLAY is :0. If not, you can always use the command "who" to retrieve the correct DISPLAY inside the script itself.

A final step is to let root uses the X environment of another user. You can do that permanently by editing/creating the file /etc/X11/xinit/xinitrc.d/localuser.sh:
Code:
#!/bin/sh
[ -x /usr/bin/xhost ] && [ -x /usr/bin/id ] &&
    xhost +si:localuser:`id -un` &&
    xhost +si:localuser:root
The last command gives permissions to use any display to the root user.

Note that you have to unlock the user at some time, using another cron job to let your son login again later.

Last edited by colucix; 07-08-2009 at 12:28 PM.
 
Old 07-08-2009, 05:37 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Colucix, quite impressive. You put at least three items in that post I have never seen before.

I am going to try something according to these directions, many thanks.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How i can lock the desktop deb1513 Linux - Desktop 2 11-27-2008 01:35 AM
How to lock down desktop question TwoFeathers Linux - Desktop 3 11-08-2007 12:18 PM
desktop lock babyphil Linux - Newbie 2 11-16-2004 10:32 PM
Making programs lock to one desktop linux-nerd Linux - Software 1 09-16-2004 03:42 PM
lock desktop DVation Linux - Newbie 6 11-08-2002 06:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration