I chose an Openbox DE at the time of login and the system took ages to load the DE. So I switched to CLI (Ctrl+Alt+F1) and rebooted my system (but I wanted to logout from the GUI and not restart the whole system).
My question is, can I issue some command at CLI to log me out from the GUI so that I can select different DE. (I don't want to restart my system every-time DE hangs.)
$ DISPLAY=:0 gnome-session-quit --force
** (gnome-session-quit:3144): WARNING **: Failed to call logout: The name org.gnome.SessionManager was not provided by any .service files
To end all user processes and be sent back to the login screen, you can use:
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:assuming that you are running GNOME on :0, which is the case in normal situations.
In Ubuntu 12.04LTS running GNOME, the command
works. The "--force" argument doesn't exist in the current update level]
In modern systemd Linux distros, the answers are all a little too complicated. The solution is one tool:
loginctl
.In a good shell you even have autocompletion, so make use of Tab to see the options and parameters and it is quite intuitive. The command to search for is
kill-session
.If you tab, you'll notice each session has an ID, but in my case it also showed the username and TTY (that is the Ctrl+Alt+number you type) and the seat.
Here is how it looks to me, e.g.:
You can tab through the sessions to find the correct one.
Otherwise, if that does not work you can find the session ID by running
loginctl list-sessions
or justloginctl
. You get something like this:I guess it's quite obvious the first column contains the session ID you need to pass to
loginctl kill-session
.This works very well if the GUI hangs and you need to force-kill it, which seems to be your use case.
If you want that to be explained in a more elaborate way here is how you can kill your own session if the GUI is not responding or you cannot use your keyboard.
Please follow takkat's suggestion. The standard is Ctrl+Alt+Backspace.
You can also run:
As an alternative, you can terminate user sessions using the following, works well to log out users except for the root user- when doing maintenance for example.
Another way,
or
which kill all users.
The real problem is that the DBUS session variables must be set and match the session you're trying to control.
I've created this script that does set the DBUS session variables from the gnome-session environment in case you want to logout other users/sessions:
How to restart Gnome-Shell from command line?
If you are in a xubuntu session or similar, must use xfce4-session-logout insted of gnome session commands, that's why you see warnings
This is what works best for me (with xfce, lightdm and ssh):
Or
If you are using Openbox then you can use
openbox --exit
which will exit the Openbox session and go back to the login manager, in my case LightDM.