16

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?

drevicko
  • 4,523

1 Answers1

17

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

Jan
  • 12,931
  • 3
  • 34
  • 39