How to logout via terminal emulator

Default featured post

In this post I want to introduce few commands for logging out from your desktop environment and back to the login screen. As you know for rebooting and turning off, some commands are available which could be easily found by searching the internet, however, for quitting from your GUI environment and backing to login screen the scenario is a little different. There is not straight forward command like reboot and halt. Therefore, the condition is much more depends on your Linux distribution, distro version, and your desktop environment.

In this post, I gather some quitting commands for different desktop environment. Finally, the source of all commands is Askubuntu.com website and I just put them in order and put them here. For accessing to the main source, please click this link.

Quiting from Gnome for Ubuntu 11.10 and above

$ gnome-session-quit

For Ubuntu 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 below command

$ gnome-session-save --force-logout

For Mate desktop

$ sudo pkill -u username

For KDE environment for Ubuntu 12.04 and above

$ qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout 0 0 0

For Xfce environment or specifically Xubuntu

$ xfce4-session-logout --logout

Or

$ xfce4-session-logout --fast

For LXDE desktop or specifically Lubuntu

$ sudo pkill -u username
$ sudo service lightdm restart

Finally, in order to be familiar about the switches or commands, refer to their manual pages or the main source link introduced above.