Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I chose an Openbox DE at the time of login and the system took ages to load the DE. So I switched to CLI (Ctrl+Alt+F1) and rebooted my system (but I wanted to logout from the GUI and not restart the whole system).

My question is, can I issue some command at CLI to log me out from the GUI so that I can select different DE. (I don't want to restart my system every-time DE hangs.)


$ DISPLAY=:0 gnome-session-quit --force

** (gnome-session-quit:3144): WARNING **: Failed to call logout: The name org.gnome.SessionManager was not provided by any .service files
share|improve this question
add comment

5 Answers

up vote 13 down vote accepted

To end all user processes and be sent back to the login screen, you can use:

kill -9 -1

Don't run it as root though, for reasons discussed here.

share|improve this answer
1  
Works great, but why? In special, why does LightDM restart after you killed everything except for init? –  Ciro Santilli Jul 7 '13 at 12:41
add comment

This can be done using the gnome-session-quit command. It needs the --force option to suppress the confirmation dialog that would appear without it.

Unlike applications run from an X terminal emulator, ending a session from a TTY requires you to append the DISPLAY variable to indicate which X display is running the session. Hence:

DISPLAY=:0 gnome-session-quit --force

assuming that you are running GNOME on :0, which is the case in normal situations.

  • In Ubuntu 12.04LTS running GNOME, the command

    "DISPLAY=:0 gnome-session-quit --logout --no-prompt" 
    

    works. The "--force" argument doesn't exist in the current update level]

share|improve this answer
    
thanks, I ran the command but i got some error. I have edited my post to include the error. Please share if I have done something wrong. –  Ankit Aug 26 '12 at 17:11
    
My bad, I did not notice you mentioned you are using openbox. Unfortunately, this command will only work with a standard Ubuntu installation (Unity/GNOME). As an alternative, you can completely shut down the GUI and thereby your session by running sudo service lightdm stop. edit: what desktop environment are you using? Openbox is just a window manager. –  Cumulus007 Aug 26 '12 at 18:36
    
i am trying to use kde/openbox or gnome/openbox. –  Ankit Aug 27 '12 at 2:42
    
Doesn't work if your terminal isn't part of the same dbus session as the gnome-session. How do you get into another dbus session? –  Zan Lynx Feb 14 '13 at 21:19
add comment

Another way,

sudo pkill -u NameOftheUser

or

sudo pkill x

which kill all users.

share|improve this answer
    
That's a bit harsh, don't you think? –  acolyte Apr 3 '13 at 17:08
    
Harsh? It's extremely silly. –  Richard Riley Jan 6 at 15:36
add comment

Please follow jokerdino's suggestion. The standard is Ctrl+Alt+Backspace.

You can also run:

$ sudo service lightdm restart
share|improve this answer
    
gdm has been replaced by lightdm. Also, ctrl+alt+backspace is disabled by default. –  Cumulus007 Aug 26 '12 at 18:36
    
@Cumulus007 Thanks, answer updated. I know ctrl+alt+backspace is disabled by default, never understood why, but I am aware of it. I am just informing the OP what the standard, most commonly used key combination is. I find it is best to stick to the standards since it makes it easier to troubleshoot. –  terdon Aug 26 '12 at 18:39
1  
Stopping lightdm will mean there's no login prompt afterwards, so he won't get the chance to log in to a different environment. –  poolie Aug 27 '12 at 0:57
1  
Fair enough @poolie, answer updated. –  terdon Aug 27 '12 at 1:00
add comment

You can use the command killall gnome-session to log out. This will work for all GNOME sessions and if I remember correctly all GNOME-related ones. It takes you right back to LightDM so you can select a new DE or a new user. :)

share|improve this answer
2  
Not the best way to logout. Check askubuntu.com/questions/69114/… –  jokerdino Aug 26 '12 at 14:25
    
Never seen this option before. I probably should start using this. I'm supposing that killall gnome-session is a forceful way to close it. –  Ryan McClure Aug 26 '12 at 14:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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