7

Part of the beauty of trying out alpha releases of operating systems is that things will break, including things we take for granted. Today it's the turn of the logout button.

So, how do you log out from the desktop environment du jour from the command line?

badp
  • 2,977
  • Maybe the name of the DE matters, who knows. – tshepang Mar 16 '11 at 07:23
  • 1
    It does matter. The version matters, too: in KDE 3 it involves dcop, in KDE 4 it's one of those long ugly dbus commands. – geekosaur Mar 16 '11 at 07:25
  • @tsephang Eh, those days I'm trying to test a number of Gnome based shells (Unity mainly, Unity 2D too), but I hoped to get a DE-agnostic answer if possible. – badp Mar 16 '11 at 07:33
  • 1
    @badp: check this out: http://stackapps.com/q/2051/5198 I say that cuz u got my name wrong. – tshepang Mar 16 '11 at 07:36
  • @tshepang Whoops. – badp Mar 16 '11 at 07:50
  • See: http://unix.stackexchange.com/questions/375/how-to-enable-killing-xorg-with-ctrlaltbackspace This will kill X, which will (hopefully) have the side-effect of logging you out. (But not from the command line, of course.) – mattdm Mar 17 '11 at 01:11

7 Answers7

3

In Ubuntu 12.04 with default gnome it is gnome-session-quit.

polym
  • 10,852
3

/usr/bin/gnome-session-save --kill works for me on Fedora 15 Alpha with gnome as my DE. Hope that helps.

Dharmit
  • 4,310
3

As long as you've got the "DontZap" set to "off" in your xorg.conf, you can use control-alt-backspace to kill your running X server. I've used this in situations when the X environment is so messed up I can't run a command. If everything is significantly wedged, you might benefit from using the Magic Sysrq keys 'k' to kill off all processes in the current VT, and if it's really wedged, you can reboot your system a bit more cleanly than a hard poweroff. Sadly, when testing the compositing WMs I did this more often than I'd like.

jsbillings
  • 24,406
3

The X server will die if you kill the session's main process, and all other X clients will die when they lose the connection to the X server.

Under Gnome (at least under Ubuntu 10.04), the session's process is gnome-session. If you're not using a desktop environment, the process you want is the session manager, or if you're not running one, the window manager. More precisely, the process you need to kill is the first client that connected to the X server.

  • Thanks for this explanation!! I'm on a bare-bones Debian install, so there IS no gdm or kdm to kill. Your explanation for why one would want to kill the display manager in the first place led me to the answer I needed. Thanks, dude!! :D – kittykittybangbang Nov 23 '15 at 18:46
2

Use killall -u $USER for logout.

don_crissti
  • 82,805
user141816
  • 31
  • 1
  • Why the downvote without comment? It logs the user out from any DE, just as requested – Chris Davies Nov 05 '15 at 19:50
  • 3
    @roaima Way late, but this can also kill other things that the user may not want to be killed, like screens or (maybe?) EMACS/URxvt daemons. – Moonchild May 03 '16 at 04:22
  • +1: even though this answer ought to explicitly warn that other things might be killed which would survive a normal logout, it's a decent last-resort measure, and is good enough if you're not trying to keep background stuff alive. – mtraceur May 26 '23 at 20:40
2

/etc/init.d/gdm restart

or

/etc/init.d/kdm restart

jet
  • 894
0

I would add:

loginctl kill-user `whoami`

This will kill all sessions for the user running the command, and don't have to think about which login name am I using.