Is there a terminal command that will log you out of your current desktop session and take you back to the login screen?
11.10 and above
11.04 and previous versions
dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1
or alternatively, you can use
--force-logout in contrast to just
--logout will not ask the user to deal with unsaved documents and so on.
is this the easiest way? no simple one line command like sudo logout?? I will never remember all that.
Yes, there is a command called logout, but it concerns the Terminal. gnome-session-save is the program that actually quits the
gnome-session, which you can of course kill, but that wouldn't qualify as logging out. :-)
Notice as well that these commands don't require you to be root.
You can always add an alias to your system if you want to have a shorter command.
~/.bash_aliases with a text editor, or create it if it isn't there, and add something like this to it:
alias logout-gnome="gnome-session-save --force-logout"
gnome-session-save was renamed to
gnome-session-quit for 11.10. Everything else in the main answer should still work with that single change.
For gnome sessions,
gnome-session-quit works well. By default it asks for confirmation and then logs you out (i.e., the
--logout argument is assumed unless overridden with
--power-off explicitly). You can also tell the command to not prompt for confirmation on logout:
--no-prompt End the session without user interaction. This only works with --logout.
gnome-session-quit is still valid in 12.04.
Since the OP didn't specify the window/desktop manager, and the gnome-session-quit might not work with all possibilities, here's a generic X-windows way to return to the login screen or chooser which I've used several times over the last several releases:
From a terminal (invoked with, variously, 'Alt-F2 + xterm, or Ctrl-T, or Crt-Alt-F1, or by right-clicking on the desktop in Nautilus and using the "open in terminal" shortcut, etc.) type
sudo pkill X
This is generally overkill for most situations. I tend to use it when I've got a hung process or when I've got to log out quickly. When I've done this, Ubuntu has politely returned me to the login screen by re-spawning X-windows.
I've not yet used the
power-off feature of the
gnome-session-quit, as I typically use
shutdown -P now for that purpose.
On Xubuntu (or whenever using an Xfce session), you can logout via the terminal by using
You must specify
--logout or the logout confirmation screen will be displayed. This will work whether you have specified 'Xubuntu session' or 'Xfce session' when you logged in with
Lightdm, as the session is still managed by the Xfce session manager.
In addition, another option will log you out as well:
If this command is issued the session is not saved, so it is normally best to use
The ability to logout using the terminal will be very useful to you, as will the other options such as suspend that are available with
For more information, see
man xfce4-session-logout or the Ubuntu manpages online.
There is a way which will work whether you are running X or you are in a TTY. There you go:
If you use
sudo service lightdm restart
if you use
gdmor in Ubuntu GNOME
sudo service gdm restart
If you use
kdmor in Kubuntu
sudo service kdm restart
The downside of this command is that it will ask for your password.