DesktopLinux
Home  |  News  |  Articles  |  Forum  |  Polls  |  Blogs  |  Videos  |  Resource Library

Keywords: Match:
Logging your kids off your Linux desktop
by Steven J. Rosen (Jul. 21. 2006)

You sit down at your desk for a relaxing session on your Linux computer, only to find that someone is already logged on. Of course, you could start a new session; Linux makes this easy. But you shouldn't have to -- the kids are long gone, to bed or playing, and your spouse never uses this computer.

This is a frequent occurrence in my house. The kids are always stopping their sessions to run off and play. Sometimes they leave things running, with annoying game music coming from the speakers or documents left unsaved.

How do you log them off when they're not around? Actually there are several ways to do it; I'll describe two ways. You'll have to become the root user for both of them.

The mean way

This method guarantees your kids will complain to you. Well, OK, any method guarantees that. But this method is especially mean because there's no chance to save the other user's work first.

Note that this method works only when the other user is running KDE. There may be a similar method for GNOME, but I haven't investigated it.
  1. Logon to KDE. (This is not strictly necessary, but it simplifies one of the later steps.)

  2. Open a terminal window and become root:

      steve@pogo:~> su -
      Password:
      pogo:~ #


  3. Now, become the user whom you want to log off. In the example below, the user is amanda:

      pogo:~ # su - amanda
      amanda@pogo:~>


  4. The next part is a bit tricky. You have to figure out which X display on which Amanda is running. In the KDE menu, select the Switch User menu entry. You'll see a list of the logged-on users, along with their X display numbers and "vt" (virtual terminal) numbers. In our example, Amanda's entry might look like "Amanda: kde (:0, vt7)" (see screenshot, below). This tells you that the X display is ":0".

    KDE's Switch User menu, showing the logged-on users along with their X display numbers and virtual terminals.

  5. Back in the terminal window, set the DISPLAY environment variable to the value of the X display; make sure to include the colon (":") as part of the value:

      amanda@pogo:~> export DISPLAY=:0

  6. Finally, issue the fatal command to kill amanda's KDE session:

      amanda@pogo:~> kdeinit_shutdown

That's it! Once you issue the kdeinit_shutdown command, all traces of the other person's KDE session will disappear. Along with any documents on which that person was working.

The kinder, gentler way

The second method simply unlocks the other user's session, allowing you to do, well, pretty much anything. I trust that you will only do good things, such as save the user's open documents, before logging the user off.

This method works whether the user is running a KDE or GNOME session, although the commands are different. However, you don't have to start a new KDE or GNOME session; you can use a terminal or even do this over telnet or ssh.
  1. At a command line, become root.

  2. Find out the process id (PID) of the other user's screen locking program. In KDE, this program is called kdesktop_lock. Run the following commands to find its PID, substituting the user name for amanda:

      pogo:~ # ps -ef | grep amanda | grep kdesktop_lock
      amanda 10689 10653 0 01:12 ? 00:00:00 /opt/kde3/bin/kdesktop_lock --forcelock


    The PID is the first number, 10689.

    In GNOME, a program called gnome-screensaver locks the user's desktop:

      pogo:~ # ps -ef | grep amanda | grep gnome-screensaver
      amanda 12182 1 0 01:19 ? 00:00:00 gnome-screensaver
      amanda 12192 12182 1 01:20 ? 00:00:00 /opt/gnome/lib/gnome-screensaver/gnome-screensaver-dialog --enable-switch


    As you can see, there are two processes shown; you want the first one, with PID 12182.

  3. Kill the locking process:

      pogo:~ # kill 12182

You're done. Now you can switch to the other user's session, save anything that needs it, and log the user off.

Maybe you'll even get a "Thanks, Dad" or "Thanks, Mom" for your efforts. Nah, these are your kids we're talking about!



Copyright (c) 2006 by Steven J. Rosen. All rights reserved. Reproduced by DesktopLinux.com with permission.



Do you have comments on this story?


Talkback here

NOTE: Please post your comments regarding our articles using the above link. Be sure to use this article's title as the "Subject" in your posts. Before you create a new thread, please check to see if a discussion thread is already running on the article you plan to comment on. Thanks!


About the Author


Steven J. Rosen has been a software developer and systems engineer for over 20 years with IBM and Lockheed Martin Corporation. For the last 11 years, he has primarily developed large government software systems on Unix using C++. He began using Linux on his home computers four years ago, starting with Mandrake Linux 8.1, and has used it ever since. He lives in Maryland with his wife and two children.


Related Stories


(Click here for further information)



Home  |  News  |  Articles  |  Forum  |  Polls  |  About  |  Contact
 

Ziff Davis Enterprise Home | Contact Us | Advertise | Link to Us | Reprints | Magazine Subscriptions | Newsletters
Tech RSS Feeds | ROI Calculators | Tech Podcasts | Tech Video | VARs | Channel News

Baseline | Careers | Channel Insider | CIO Insight | DesktopLinux | DeviceForge | DevSource | eSeminars |
eWEEK | Enterprise Network Security | LinuxDevices | Linux Watch | Microsoft Watch | Mid-market | Networking | PDF Zone |
Publish | Security IT Hub | Strategic Partner | Web Buyer's Guide | Windows for Devices

Developer Shed | Dev Shed | ASP Free | Dev Articles | Dev Hardware | SEO Chat | Tutorialized | Scripts |
Code Walkers | Web Hosters | Dev Mechanic | Dev Archives | igrep

Use of this site is governed by our Terms of Service and Privacy Policy. Except where otherwise specified, the contents of this site are copyright © 1999-2011 Ziff Davis Enterprise Holdings Inc. All Rights Reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff Davis Enterprise is prohibited. Linux is a registered trademark of Linus Torvalds. All other marks are the property of their respective owners.