How can I logout from a graphical environment from the command line?

20,785

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

/etc/init.d/gdm restart

or

/etc/init.d/kdm restart

Solution 5

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.

Share:
20,785

Related videos on Youtube

badp
Author by

badp

I'm a he/him Senior Developer at Booking.com. I publicly whine on Twitter (@badp) and discord (bp#0001). It should go without saying that the opinions stated by me are my own and not necessarily those of my employers past and future, but apparently it doesn't and, while no one asked me to put this disclaimer here, I'll just put it over here with the rest of the fire.

Updated on September 17, 2022

Comments

  • badp
    badp over 1 year

    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?

    • tshepang
      tshepang about 13 years
      Maybe the name of the DE matters, who knows.
    • geekosaur
      geekosaur about 13 years
      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.
    • badp
      badp about 13 years
      @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.
    • tshepang
      tshepang about 13 years
      @badp: check this out: stackapps.com/q/2051/5198 I say that cuz u got my name wrong.
    • badp
      badp about 13 years
      @tshepang Whoops.
    • mattdm
      mattdm about 13 years
      See: unix.stackexchange.com/questions/375/… This will kill X, which will (hopefully) have the side-effect of logging you out. (But not from the command line, of course.)
  • roaima
    roaima over 8 years
    Why the downvote without comment? It logs the user out from any DE, just as requested
  • kittykittybangbang
    kittykittybangbang over 8 years
    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
  • Moonchild
    Moonchild almost 8 years
    @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.