There are several ways to log out of an Ubuntu desktop session but most are so obvious they don’t need a guide explaining them!

What you may not know, however, is how to logout of Ubuntu from a terminal (or to log out of GNOME on any Linux distro that uses it).

Heck, I didn’t until around a minute ago.

To log out from a terminal open the Terminal app and run this command:

gnome-session-quit

After you hit enter the (standard GUI) logout dialog will appear, replete with a 30 second countdown. The timer gives you time to save any unsaved work, finish up any tasks, and exit apps cleanly — y’know, to ensure you safely log out of your Ubuntu user session the right way.

But if you’re in a hurry…

To logout of Ubuntu from the command line immediately (i.e. as soon as you hit enter) open the Terminal app and run the same command, but this time add the --no-prompt flag to the end, like so:

gnome-session-quit --no-prompt

As soon as you lift your finger off of the enter key you will be forcibly logged out. No ifs, no buts, and no maybes. Any unsaved changes, running apps, terminal commands, or other endeavours that are active will be killed.

And you get dropped back to the GDM login screen.

Simple, really!

So why am I writing a post about it?

Well, I was building some development GNOME components so I could try things out (and take some screenshots) for an upcoming article. Once I was done building none of the ‘obvious’ GUI ways to log out of GNOME (e.g., the Status Menu, application screen shortcuts, etc) would respond.

And yes, I tried to patient 😅.

I turned to Google to learn “how to log out of GNOME from terminal”. I thought some rich snippet to give me an immediate answer.

It didn’t.

Instead, Google fed me links to (admittedly useful) ‘log out’ guides that walk through (what felt like) sixteen different ways to do the same task, when all I wanted to know was this specific one.

So to help anyone else who finds themselves in a similar situation (though probably just myself in 6 months when I forget again) I figured I’d throw up a quick guide to show you how to log out of Ubuntu from the command line, and, er, well, that’s it!

FIN.

How To

terminal tips

ubuntu basics