19

In Ubuntu 11.04, Ctrl-Alt-Del gives me a menu with shutdown, hibernate, suspend and restart, but no logout. Is there a key combination to logout of Ubuntu? Is there a way to provide one?

1
  • If future searchers want to know. I can type Ctrl+Alt+L in 12.04 to lock screen. – AWE Aug 26 '14 at 6:33
24

Creating custom keyboard shortcuts:

For 12.04 LTS and later:

To add a new shortcut open System Settings -> Keyboard and choose the Shortcuts tab:

enter image description here

Press the '+' sign on the bottom left to enter the name of your custom shortcut and the command you want to run (e.g. gnome-session-quit --logout --no-prompt). After having applied this you are able to select the line of your new shortcut. Then press the desired key combination. In case the key combination already exist we will have to delete this first.

For 14.04 LTS and later:

In a default Unity session the new logout dialog is presented needing another at least two keystrokes to select poweroff from the menu:

enter image description here

The old dialog with a 60 s timeout will only be displayed in a gnome-flashback session.

3
  • Thanks for the effort of putting this answer together! I'd be interested to know if "System Settings -> Keyboard -> Shortcuts tab"... described here has the same effect as "Gnome Control Center -> Keyboard" described by @enzotib (for 11.10) – drevicko Oct 20 '11 at 2:54
  • @drevicko The menu entry System Settings calls the Gnome Control Center, so yes, its the same. – Takkat Oct 20 '11 at 6:11
  • Excellent It the same trick for 12.04. – Papachan May 6 '12 at 13:07
5

In Ubuntu 11.10 you could write a script containing

#/bin/bash
gnome-session-quit --logout --no-prompt

make it executable with chmod +x script-name, then set a global shortcut to execute this script in Gnome Control Center -> Keyboard.

In previous Ubuntu versions there was gnome-session-save --logout.

2
  • In 11.10 the default action on Ctrl+Alt+Del is to logout. – Takkat Oct 19 '11 at 7:09
  • @Takkat: you're right, I assumed the OP do not want it to ask for confirmation. – enzotib Oct 19 '11 at 7:26
4

In Ubuntu 1204 there are two out-of-the-box solutions:

  1. "Run a command" technique:

    Alt-F2 | type gnome-session-quit

  2. "Indicator menu" technique:

    Alt-F10 | arrow right or left to gear icon | arrow down to Log Out...

In each case, confirm logout by hitting Enter. A bug in Ubuntu for #1 is that if you login and do nothing and hit Alt-F2 you get Dash (to run programs). Just hit Esc and try again with Alt-F2 and you'll get the "Run a command" instead this time.

1

If you are using Unity (the default environment in Ubuntu 11.04 and later) then you can press the Super key (aka the Windows key) to bring up the dash, type in "log" and the first option is "Log Out" so just press Enter. This will bring up a dialog box to confirm whether you want to log out, with the "Log Out" button already selected, so press Enter again. And you're logged out.

2
  • "Log Out" does not appear in my dash.. – drevicko Oct 20 '11 at 2:52
  • @drevicko: I've only actually tested this on 11.10, so it is possible it doesn't works with 11.04. – Hamish Downer Oct 20 '11 at 16:55
1

Another way is to restart lightdm. In 14.04 that would be sudo service lightdm restart and in 15.04 systemctl restart lightdm

1

I think you can just make custom shortcut for gnome-session-quit --logout --no-prompt without any bash scripting.

0

If the GUI is not actually responding anymore, all these shortcuts here won't work. Also they all require you to think of that before you want to use it, which is bad, if you are in a problematic state, where you e.g. cannot use the mouse anymore or GNOME (your desktop UI) freezes or so.

However, you can usually still change the TTY to a different one that has a CLI interface, login and kill the session there.

Step by step

  1. Press Ctrl+Alt+number to go to a different TTY.
    That (TTY) number best to try is, depending on your version and how many users you have logged in currently either the number 1 (<= Ubuntu 17.10) or 3 (> Ubuntu 17.10). Either read up the details behind that or just try them one-by-one or randomly, just be a little patient as switching to a different TTY can take some seconds.
    Or, of course, just try a high number that is likely always there (like 5 or so). And remember the number you've pressed, in order not to accidentally kill yourself later.
  2. Now login by typing your (or any) user name and password.
  3. Now run loginctl like this loginctl kill-session XY by replacing XY with the session number you want to kill.
    As you likely don't know that magic number by heard, you can read here how to find it. The TL;DR Is: Use tab to autocomplete it or use loginctl list-sessions and especially have a close look at the TTY number to know what to kill.

If you need, you may prepend the commands with sudo, e.g. if you try to kill another's users session. Though loginctl will deal with that by itself and ask you for a password if you need additional authentication.

Possibly do not forget logout from your "recovery TTY" you've used (just type exit or logout – or, of course, kill your own session), as you likely won't need it anymore.
If you don't and someone clever sneaks in, they can access all your data there, as these terminal sessions usually won't lock/protect themselves.

Somewhere (likely TTY1 in new Ubuntu versions; Ctrl+Alt+1) is your login screen. In case you need to go back to it…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.