14

I have a (graphical) login session running on an office computer, and I'd like to log it out to save on a few computer resources.

I can ssh to the office box, but when I try gnome-session-quit I get this:

$ gnome-session-quit --logout --no-prompt

** (gnome-session-quit:18500): WARNING **: Command line `dbus-launch --autolaunch=fca99a51622d1930b068883b00000005 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n

** (gnome-session-quit:18500): WARNING **: Unable to start: Cannot open display: 

Makes sense as my $DISPLAY is empty (as it's a headless ssh session). When I run w, I see that the gnome-session is running on tty7. Is there a way I can pretend to be tty7 and initiate a logout? Is there a better way to do this?

2
  • Usually with w, I see some line to this effect: muru :0 Wed20 ?xdm? 11:15m 1.10s gdm-session-worker [pam/gdm-password], the :0 being my relevant $DISPLAY. Don't you? You can also try pgrep -fa X and see what X is running with.
    – muru
    Sep 22, 2014 at 6:58
  • 1
    the entry from w with gnome-session had tty7 as the display, but the session had several other entries with :0 (terminals open I guess?). Checking the time column from w I realised :0 was the graphical session for sure (:
    – drevicko
    Sep 22, 2014 at 7:10

1 Answer 1

15

After logging in with ssh, run:

env DISPLAY=:0.0 gnome-session-quit --logout

This will force a logout on the remote machine just as if you had logged out from the menu (but without prompting). You may need to run gnome-session-quit with --force-logout if there's an application with, for example, unsaved work, that would otherwise prevent a clean logout.

If you use a very old version (<2011) of GNOME, then you need to

env DISPLAY=:0.0 gnome-session-save --logout

... because gnome-session-save was renamed to gnome-session-quit in 2011.

Source

5
  • 2
    On the office box, there is no gnome-session-save, but there is a gnome-session-quit which (with the rest of your answer) did the trick. I forgot to mention it's running Ubuntu 12.04 - perhaps that's why?
    – drevicko
    Sep 22, 2014 at 7:07
  • @drevicko probably a typo. It's still -quit on a 12.04 box I have.
    – muru
    Sep 22, 2014 at 7:15
  • 1
    gnome-session-save was renamed to gnome-session-quit in 2011: mail.gnome.org/archives/desktop-devel-list/2011-February/…
    – Jan
    Sep 22, 2014 at 7:25
  • 2
    @muru: updated answer accordingly
    – Jan
    Sep 22, 2014 at 7:28
  • Note that if the session is run under a session manager like Xvnc, it may not be on display 0.0. You can often find the display by doing a ps ux listing to find the process and see which display number is listed with the process. For example, my Xvnc process was listed as Xvnc :10 -geometry..., so I had to use env DISPLAY=:10.0 ....
    – Bloodgain
    Sep 3, 2020 at 1:01

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.