Log Off Your Kids

Discuss this article in the SJRNet Article Forum

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 occurence 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 amanda is running on. In the KDE menu (KDE 3.5 and above), 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 Figure 1 below). This tells you that the X display is ":0".

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

    If you're not running KDE 3.5 yet, go to a command line and issue the who command:

    steve@pogo:~> who
    amanda   :0           2006-07-24 14:54 (console)
    amanda   pts/1        2006-07-24 14:55
    ...

    The first line of output indicates that amanda is running on display ":0".


  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!

Discuss this article in the SJRNet Article Forum