How to log out current user?

28,113

If you are using gnome,

   gnome-session-quit

or

  gnome-session-save --force-logout

or also

  dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1

If you use KDE,

  qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout -1 -1 -1

In LXDE,

  lxde-logout

In XFCE,

  xfce4-session-logout

Whatever your desktop environment, you can define an alias to make your life easier. Edit the file /home/your_name/.bashrc,

and place in it, toward the end, the following line:

  alias mylg='gnome-session-quit'

or whichever command you wish. Source the file,

 source .bashrc

and you now have a brand new command, mylg, which will log you out.

Share:
28,113

Related videos on Youtube

cdonts
Author by

cdonts

Updated on September 18, 2022

Comments

  • cdonts
    cdonts over 1 year

    I'm very very new to the linux world. I have just installed Ubuntu 12.04 and I was wondering how to log out my user using the terminal. I searched the web and all the sites say that I should run the command logout or exit. But here's the problem. Using logout throws me a message saying I should use exit. And using exit just closes the terminal, I'm still logged in.

    How can achieve this?

    Thanks in advance.

    • Rudu
      Rudu over 10 years
      exit should be the correct term, when you say "log out" do you mean leave the XWindow (GUI) system?
    • cdonts
      cdonts over 10 years
      Hi thanks for your answer. Yes, I mean that or going back where you need to put your user password to log in (just like a log out in Windows).
    • MariusMatutiae
      MariusMatutiae over 10 years
      In the upper right hand corner there are several small icons. Click on one them at a time, one will present you with the options Shutdown/Logout/restart computer.
    • cdonts
      cdonts over 10 years
      Thanks for your answer but I'm asking about doing that from the terminal/command line.
  • cdonts
    cdonts over 10 years
    The first command works on Ubuntu. Thanks a lot!