There is no specific command to logout in an Ubuntu system.

Why ?

Here’s how it works. The desktop you’re seeing is a separate software. They are called Desktop Environments (DE). The default DE of Ubuntu is Unity from Ubuntu’s 11.04 versions. Before it was GNOME. There are many DEs for Ubuntu. Some of them are :

  • Openbox
  • XFCE
  • LXDE

and many more.. There are also separate Login Managers to provide the login screen while Ubuntu is loaded. When you log in, the Login Manager starts the default DE set up on your system and when this DE program is closed or terminated, it will go back to the Login Screen or Login Manager.

So, as to log out the user, you have to terminate the DE program. This is why there is no special command to log out.

How ?

Now, let me show you how to terminate the DE program. It’s very easy, just like closing an application.

First, we need to find which DE Ubuntu is using on your system. You can find it from the small Ubuntu icon on your login screen just near Username field. Here are some other clues :

  • Unity – Stylish Sidebar with icons and the Dashboard menu appears when you press Super/Windows key
  • GNOME – A Footprint logo on desktop
  • XFCE – There’s a mice logo somewhere on your desktop
  • LXDE – Have a Windows like Panel at the bottom

And here are the program names of the above DE except for Unity :

  • GNOME – gnome-session
  • XFCE – xfce4-session
  • LXDE – lxsession

Open a Terminal (CTRL + ALT + T) and do one of the two methods shown below :

Method 1

Do the following command :

ps aux | grep <DE_program>

Replace “<DE_program>” in the above command with the program name of DE.

You will get a list of processes running. Find the DE program name from the list. Get the process id of that process from column no 2. Suppose the id is 1728. To logout you should kill the process. For that use the following command:

kill <process_id>

If the process id is 1728 the code will be :

kill 1728

What the above command does is that it terminates the DE program.

Method 2

You can directly kill the DE program by mentioning it’s program name, like this :

pkill <DE_program>

Replace “<DE_program>” in the above command with the program name of DE and execute it. This will also kill the program just like the 1st method.

Unity

Unity has some special consideration. The log out can be initiated without killing any program. Run the command :

gnome-session-quit --no-prompt

The above will work on Unity even though the command is for GNOME, because the program is included with every installation of Ubuntu.