How can I logout from the GUI using CLI?

To end all user processes and be sent back to the login screen, you can use:

kill -9 -1

Don't run it as root though, for reasons discussed here.


This can be done using the gnome-session-quit command. It needs the --force option to suppress the confirmation dialog that would appear without it.

Unlike applications run from an X terminal emulator, ending a session from a TTY requires you to append the DISPLAY variable to indicate which X display is running the session. Hence:

DISPLAY=:0 gnome-session-quit --force

assuming that you are running GNOME on :0, which is the case in normal situations.

  • In Ubuntu 12.04LTS running GNOME, the command

    "DISPLAY=:0 gnome-session-quit --logout --no-prompt" 
    

    works. The "--force" argument doesn't exist in the current update level]


Please follow takkat's suggestion. The standard is Ctrl+Alt+Backspace.

You can also run:

$ sudo service lightdm restart