I'm new with dbus, and saw different ways to log out from terminal depending on desktop env. But I'm curious is there any way to log out from any desktop env using dbus messages?


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


dbus-send --print-reply --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout int32:0 int32:0 int32:0

Is there any command that would work on every desktop env (like using system dbus)?

  • thank you very much for reply, could you please provide how can it be done on systemd setups? – user173408 Jun 25 '16 at 11:46

On systemd setups you should be able to forcibly terminate a session via logind dbus interface:

dbus-send --system --print-reply --dest=org.freedesktop.login1 \
/org/freedesktop/login1 'org.freedesktop.login1.Manager.TerminateSession' \

where c2 is the session ID string; to get the session ID you could run

    SESSION       UID  USER           SEAT            
        c1        120  gdm            seat0           
        c2       1000  don            seat0           

2 sessions listed

or, if you prefer to do it also via dbus interface:

dbus-send --system --print-reply --dest=org.freedesktop.login1 \
/org/freedesktop/login1 'org.freedesktop.login1.Manager.ListSessions'

which returns something like

   array [
      struct {
         string "c1"
         uint32 120
         string "gdm"
         string "seat0"
         object path "/org/freedesktop/login1/session/c1"
      struct {
         string "c2"
         uint32 1000
         string "don"
         string "seat0"
         object path "/org/freedesktop/login1/session/c2"
  • One more question Please, on My 14.04 ubuntu I have gnome and KDE, on gnome the logout command worked, I checked and I have systemd-logind, on KDE I have that process too, but ListSessions returns empty array and logout command doesn't work. – user173408 Jun 25 '16 at 13:24
  • @user173408 - I only have gnome installed and I'm not familiar with other DEs so no idea why it doesn't work in KDE... apparently there are some problems with systemd-logind – don_crissti Jun 25 '16 at 14:47
  • One more question, :) sorry for being annoying, My problem is that I'm logged in as user A and create process as user B, which creates session for user B, I want to kill session using dbus messages from that process, I downloaded d-feet, and I can see that after session is created /org/freedesktop/user/1002 is added in system dbus, but using Terminate in it brings error 'GDBus.Error:org.freedesktop.DBus.Error.UnknownObject: Unknown user' but using Terminate for user A works fine. – user173408 Jun 25 '16 at 15:50
  • I'm talking about ubuntu of course. – user173408 Jun 25 '16 at 17:43
  • @user173408 - I saw your other post but I can't really help you as I don't even have startx on my laptop... I'm not sure I understand the purpose of this exercise but anyway, using gnome built-in feature switch user to login multiple users, I can terminate another user session (or another user) if I su - to that user. Also, on my system it's /org/freedesktop/login1/user/_1002 (note the underscore in front of the user ID). – don_crissti Jun 25 '16 at 18:57

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.