0

I want to log out the user session of a remote Ubuntu 12.04 x64 (laptop) by ssh'ing and running a command.

I know I can reboot with a simple sudo reboot but don't want to if I can help it, I'd rather just log out and back in.

gnome-session-quit fails with an error that it can't find the display, and gnome-session-quit DISPLAY=:0.0 also fails with the error:

> gnome-session-quit DISPLAY=:0.0

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

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

Only other thread I could find similar to this doesn't have any more answers than what I've tried. Anyone know the way to do this?

bgibson
  • 4,787

1 Answers1

1

I think you need to specify the value of the DISPLAY variable before the command - you will also need to specify options --logout --no-prompt else it will prompt for confirmation on the local display

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

If that fails, provided you have administrator privileges you could always just restart the display manager e.g. sudo service lightdm restart (although that will terminate ALL its managed sessions).

Obviously you should verify that the display number really is :0 if you have not already done so

steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • Thanks, how do you check the display number? Took a wild guess and echo $DISPLAY wasn't it. – bgibson Oct 24 '13 at 05:39
  • 1
    The $DISPLAY variable won't be set automatically if you're in an SSH session - you can look for the X server process(es) /usr/bin/X in the output of the ps command, usually the primary server runs in tty7 so ps -ef | grep '[t]ty7' for example – steeldriver Oct 24 '13 at 06:37